Updating Twitter Status By CURL

Anyone can update their twitter status by simply log in to twitter and update his/her status. But if you require to update your status by simply typing your status and clicking on a button name “Update my status” from your blog or fr0m outside any application rather than twitter than what you will do?Remember your manual twitter status update strategy.First you have to log in than you can update your status.But if you are  a programmer you can simply do it by  writing few lines of code.I have shown here the PHP style.Here i have not followed the usual way, for example writing a stand alone class for CURL and also a CURL exception class but believe me it will work…This is the basic….

<?php

/* settings */
$username = ‘your_user_name’;
$password = ‘your_pass’;
$format   = ‘xml’; //alternative: json
$message  = ‘your message’;

/*******Curl version*********/
$curl = curl_init(‘http://twitter.com/statuses/update.xml’);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, ‘status=’.urlencode($message));
curl_setopt($curl, CURLOPT_USERPWD, $username.’:’.$password);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(‘Expect:’));

$xml = curl_exec($curl);
print $xml;
/******End*****/
curl_close($curl);

after successfully updating your status a xml will be returned.By processing the xml  node you can show a message like  “You status has been updated successfully.”

Enjoy…..

Advertisement

~ by Kal Purush on April 12, 2010.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.