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.
$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.
If you liked this article, you may also like: