Thirupathi
Joined: 01 Dec 2009 Posts: 116
|
Posted: Fri Mar 12, 2010 8:57 am Post subject: Get the status from twitter using PHP script |
|
|
How to get the twitter status:
1)First you have to create an account in http://www.twitter.com,NOw you have an id and
password for twitter account.
2)You can get the status of your account from the twitter site using the fallowing php
script.
<?php
/*
The bellow is the php code to post our site updates on the twitter.com,To run this you
have to activate the curl in php.ini file that is uncomment the curl extension.
*/
$username = 'your twitter username';
$password = 'password';
$status = urlencode(stripslashes(urldecode('Hi thirupathi, This is my tweet for
testing on localhost')));
if ($status) {
$tweetUrl = 'http://www.twitter.com/statuses/update.xml';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "$tweetUrl");
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status");
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($curl);
$resultArray = curl_getinfo($curl);
//print_r($resultArray);
if ($resultArray['http_code'] == 200)
echo 'Tweet Posted';
else
echo 'Could not post Tweet to Twitter right now. Try again later.';
curl_close($curl);
}
?>
Thanks & Regards,
Thirupathi.J |
|