Amit Dhamu

Writes Code

Update Twitter Status

$username = 'YOUR_TWITTER_USERNAME';
$password = 'YOUR_TWITTER_PASSWORD';
$message = "This is my new tweet";

function tweet($message, $username, $password) {
    $context = stream_context_create(array(
        'http' => array(
        'method'  => 'POST',
         'header'  => sprintf("Authorization: Basic %srn", base64_encode($username.':'.$password)).
                      "Content-type: application/x-www-form-urlencodedrn",
        'content' => http_build_query(array('status' => $message)),
       'timeout' => 5,
        ),
    ));
    $ret = file_get_contents('http://twitter.com/statuses/update.xml', false, $context); 
    return false !== $ret;
}

echo tweet($message, $username, $password);


twitter / php / tweet

← Optimise Site Using DEFLATE Flickr Photo Search API →