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…..
