Note: This method of posting to Twitter is fully depreciated. You should now use OAuth instead. Read more here.
Twitter has a very cool and robust API that makes building applications a breeze. More on that in another post.
More often than not, people are after a simple method of posting data to Twitter using the API quickly and easy – and easy it is.
Using the following code, making use of CURL, you can effortlessly post updates to Twitter from basic web applications. I use it on a number of sites and it’s proven to be very effective… even though it can be a little slow.
The use of any communication with the API in any way other than OAuth may be limited although Twitter are yet to determine if and when the service will be depreciated.
$twittername = "your-twitter-username"; $twitterword = "your-twitter-password"; $message = "your twitter message"; $url = 'http://twitter.com/statuses/update.xml'; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$url"); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message"); curl_setopt($curl_handle, CURLOPT_USERPWD, "$twittername:$twitterword"); $buffer = curl_exec($curl_handle); curl_close($curl_handle);
If you have any problems let me know. I have lots of Twitter code coming soon.
|
|
Download: Download: Post to Twitter with Curl |
If you liked this article, you may also like:


Thanks for the info. Works great!