Simple Status Update in Twitter Using PHP
Welcome! Thank you for visiting!
Follow me at Twitter
Subscribe to my full feed.
Here is a sample PHP snippet that will let a twitter user update their status using PHP code. I have it simply saying hello today is and the date. I’m thinking about running it from a cron script in an automated fashion in conjunction with another site that I run. To see the code I used click the more button unless you’re luckily enough to be sent to this post directly.
< ?
$today = date("l F j, Y");
// Set username and password
$username = 'username';
$password = 'password';
// The message you want to send
$message = 'Hello today is '.$today;
// The twitter API address
$url = 'http://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'http://twitter.com/statuses/update.json';
// 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 'message';
} else {
echo 'success';
}
?>
What are some cool ideas for this? I’m thinking maybe it could tweet today’s weather forecast or something. I would like to get more in-depth and create an interactive bot just for fun.






