Monday, August 6, 2012

How To: Update Your Twitter Status Using PHP.




Twitter is social networking website which keeps your followers with you. Twitter provides an extensive API using which we can update twitter status through PHP code.

 


// Set your username and password

$username = 'YourAccount';

$password = 'YourPassword';

$message = 'Codeigniter Help'; // Which you want to update

$url = 'http://twitter.com/statuses/update.xml';

// Set up and execute the curl process

$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, "$username:$password");

$buffer = curl_exec($curl_handle);

curl_close($curl_handle);

// check for success or failure

if (empty($buffer)) {

echo 'Failed !';

} else {

echo 'Status has been updated.';

}

?>



1 comment:

  1. I now own a business of my own with the help of Elegantloanfirm with a loan of $900,000.00 USD. at 2% rate charges, at first i taught with was all a joke until my loan request was  process under five working days and my requested funds was transfer to me. am now a proud owner of a large business with 15 staffs working under me. All thanks to the loan officer Russ Harry he is a God sent, you can contact them to improve your business on.. email-- Elegantloanfirm@hotmail.com.

    ReplyDelete