Twitter using CURL via their API

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
Description: Post to Twitter with Curl.
Author:InteNoetics.com
Category: PHP code
Date: January 2, 2010

If you liked this article, you may also like:

  1. Post to Twitter using OAuth
  2. Determine the Relationship between two Twitter Users
  3. Include Twitter Data on your Website
  4. Include a Twitter word cloud in WordPress using shortcode
  5. Count the number of times your page is Tweeted via the TweetMeme API
About Marty

is a passionate web developer from Sydney, Australia. He owns about 400 websites and makes a healthy living from working the web. As a day job, he works as a pilot for an international airline. You can follow Marty on Twitter or Google+.

Comments

  1. Nigel says:

    Thanks for the info. Works great!

Trackbacks

  1. [...] or another and, until a few months ago, I did so via the API that they retired on September 1st. Previous means of sending tweets to Twitter no longer work. The only method of integrating applications now is via [...]