Thursday, October 22, 2009

How to update twitter status using php

The following lines of code are used to update your status in twitter.

//Text to be updated on twitter
$status = "Hi this is the text to be updated";
//your twitter username
$username = "xxxxusername";
//your twitter password
$password = "password";
$postvars = "status=".$status;
$url = "http://twitter.com/statuses/update.xml";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);           
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);  // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  // RETURN THE CONTENTS OF THE CALL
$res=curl_exec($ch);
curl_close($ch);

2 comments:

  1. Here is much more easier method http://v8no.com/messenger.php

    ReplyDelete
  2. Fast and easy way to update status in twitter with PHP in 2 steps - http://ayauho.com/~ay

    ReplyDelete