Friday, September 05, 2008

IM Bot to update Twitter

So for all of you twitters out there here is a little tutorial how to write your own IM bot to easily update twitter using IM client. I know i knoq you can use the official IM twitter bot BUT it is down right now. So, why not use your own.

First of all read post How to Write Your Own IM Bot in Less Than 5 Minutes

Follow all the steps for creating your own im bot.
Next add the following code to the .php script from the IM Bot blog post.
// Set username and password
$username = 'user';
$password = 'pass';
// The message you want to send
$message = $_REQUEST['msg'];
// The twitter API address
$url = 'http://twitter.com/statuses/update.xml';

$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 'message';
} else {
echo 'success';
}
*/
?>

Thats it!
enjoy!