Posted by: Md. Masud on: May 10, 2008
Twitter is one of the micro blogging site in the world. Actually people used Twitter answering a question “what are you doing?”. Twitter has done some great thing like included jaber interface to post directly from google talk or other IM who support jaber API. Twiter also provide a small API, by which you can post your msg from other site.
The API is looks like this which is collected from google code. Here is a simple view
function postToTwitter($username,$password,$message)
{
$host = "http://twitter.com/statuses/update.xml?source=SITE_NAME&
status=".urlencode(stripslashes(urldecode($message))); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $host); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_POST, 1); $result = curl_exec($ch); // Look at the returned header $resultArray = curl_getinfo($ch); curl_close($ch); if($resultArray['http_code'] == "200"){ $twitter_status='Your message has been sent!
<a href="http://twitter.com/'.$username.'">See your profile</a>'; } else { $twitter_status="Error posting to Twitter. Retry"; } return $twitter_status; }
I have recently add this features to one of my application development and hereby i share this knowledge with all of you. good luck
NB: To see the code working you should activate the curl library from php.ini
Recent Comments