Twitter offers a handy dandy API for posting to itself. It’s not hard to work with (you just have to organize your data the right way).
You need to have a few variables set up prior to running this.
$message (what you are posting to twitter — a day or so ago I provided the code to make tinyurls)
$twitter_user = Your twitter Username
$twitter_password = Your twitter password
If you have those three variables set you can call the code below and post to twitter with their api url and a wee bit of curl. Here is the code to do it:
$twitter_api_url = “http://twitter.com/statuses/update.xml?status=”.urlencode(stripslashes(urldecode($message)));
$twitter_data = $message;
$ch = curl_init($twitter_api_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $twitter_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, “{$twitter_user}:{$twitter_password}”);
$twitter_data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
//Let’s print out where we posted and what!
echo ‘Posting Message: ‘.$message.’<br> to <br> http://www.twitter.com/’.$twitname.”;
// Let’s print out an error message if things didn’t go well.
if ($httpcode != 200) {
echo “<strong>Don’t Panic!</strong> Something went wrong, and the tweet wasn’t posted. You Failed.”;
}
That’s really it. It will post your message to twitter. You can store your variables in an array, or a database, or a text file. Along with all your messages and have it go do it’s thing.
2 Responses to How to make your own Twitter Poster in PHP with Curl
Leave a Reply Cancel reply
Codebank Latest Releases
Codebank Recently released: Location Generator Magic Keyword Plugin Magic Rss Linker 4 new tutorialsCategories
- 30 Day Website Network
- Black Hat Experiments
- Changing Affiliate World
- CodeBank
- Contests
- Digest
- Facebook Programming
- Featured Articles
- Features
- Internet Marketing Tips
- Network Building
- Network Progress Report
- Newbie Corner
- Online Tools
- Overview
- Rambling
- Rss Marketing
- Tutorials
- Uncategorized
- What Are We Going To Do Today?
Rss Notifications




One thing you can do is in the error section is have it give you a notice (through mail, text file, something). That way if your twitter account gets a problem like being banned or whatever you can stop trying to post to a dead account.
Ken Reno put together a couple of WordPress plugins autopost to your WP blog and then will automatically post to your Twitter account. It allows you to set the frequency of updating your blog therefore the number of tweets is regulated by the updates. Look it over here… http://www.commissionsautomator.com/?e=leonh
For such a cheap price, I think it would be the thing to do. Plus it is a whitehat way to do it in my opinion.
Peace,
Leon