Update Twitter using command line or PHP

by Rekha 2009-11-07 14:46:28

The easiest way to update your Twitter account is to just call curl from the command line with this command.

Suppose your username is xxx and password is mypassword,

curl --basic --user "xxx:mypassword" --data-ascii
"status=This Twitter update brought to you by curl on the command line"
"http://twitter.com/statuses/update.json"




To update your Twitter status with PHP you are going to want to do the same sort of thing but with a bit more typing.


<?php
$username = 'xxx';
$password = 'mypassword';

$update = 'This Twitter update is from a php script using curl';//you can also get the updates from a html form and use post to get the value.

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

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "status=".$update);
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
$result = curl_exec($ch);
curl_close($ch);

if($result)
echo 'success';

?>;

Tagged in:

1102
like
0
dislike
0
mail
flag

You must LOGIN to add comments