Really frustrated: Help writing a sample twitter app

Posted by Jack on Stack Overflow See other posts from Stack Overflow or by Jack
Published on 2010-03-25T12:25:27Z Indexed on 2010/03/25 12:33 UTC
Read the original article Hit count: 286

Filed under:

I have installed WAMP. I have enable cURL in php.ini. I want to implement a twitter app that posts a new status message for a user. Here's my code

<?php 
function updateTwitter($status)
{ 
    $username = 'xxxxxx'; 
    $password = 'xxxx';
    $url = 'http://twitter.com/statuses/update.xml'; 
    $postargs = 'status='.urlencode($status); 
    $responseInfo=array(); 
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXY,"localhost:80");
    curl_setopt ($ch, CURLOPT_POST, true); 
    // Give CURL the arguments in the POST 
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);
    // Set the username and password in the CURL call 
    curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password); 
    // Set some cur flags (not too important) 
    $response = curl_exec($ch); 
    if($response === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo 'Operation completed without any errors<br/>';
}

    // Get information about the response 
    $responseInfo=curl_getinfo($ch); 
    // Close the CURL connection curl_close($ch);
    // Make sure we received a response from Twitter 
    if(intval($responseInfo['http_code'])==200){ 
        // Display the response from Twitter 
        echo $response; 
    }else{ 
        // Something went wrong 
        echo "Error: " . $responseInfo['http_code']; 
    } 
curl_close($ch);
    }

updateTwitter("Just finished a sweet tutorial on http://brandontreb.com");

?>

I am getting the following output

Operation completed without any errors
Error: 404 

Please help.

© Stack Overflow or respective owner

Related posts about php