Update Your Twitter Status programmatically Using Twitter Basic Authentication With PHP

It is very easy to programmatically update your twitter status using PHP. Here is the ready to use code that can be used to make auto-tweet; may be you can write the custom code that fetches random blog post from your blog and tweet it on your twitter. It is currently making use of twitter basic authentication. It is good to use OAUTH. However, this basic authentication is still valid.

$username = ‘twitterusername’;
$password = ‘twitterpassword’;
$format = ‘xml’; //alternative: json
$message = $message . urlencode($url);
$result = shell_exec(‘curl http://twitter.com/statuses/update.’.$format.’ -u ‘.$username.’:’.$password.’ -d status=”‘.str_replace(‘”‘,’\”‘,$message).’”‘);
echo $result;

Mayur Gondaliya - CTO - CaseTronyx, Inc. Director - ExaSpring Information Services Pvt. Ltd. Web Investor. Software Engineer. Workaholic. Insomniac.

3 Comments


  1. Mayur Gondaliya
    Aug 17, 2010

    As of 16th August 2010, the basic authentication is no longer supported. Use OAUTH instead of basic authentication.


  2. nithu
    Mar 09, 2011

    I’m using your code but it showing “Could not authenticate you” error.


  3. nithu
    Mar 09, 2011

    Basic authentication is not supported for my application,please guide me.

Leave a Reply