Categories
PHP

Updating Twitter status using PHP CLI

Here’s the source file :

<?php
$username = $argv[1];
$password = $argv[2];
$message = $argv[3];
$tweetUrl = “http://{$username}:{$password}@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={$message}”);
$result = curl_exec($curl);
?>

How to Use ?
Save the file as “twitter.php”.

php twitter.php twitter_username twitter_password “Status Update !!”

NB: If you are posting a multi word status ( which has space ), don’t forget to wrap the sentence inside double quotes. Otherwise the first word of the sentence will be posted alone. The codes require cURL extension loaded.