Post to Twitter from PHP

February 07, 2010 0 Comments Category: Geek News, Open Source, Usability, software

  Post to Twitter PHP Function (915 bytes, 41 hits)

Looking to Tweet from PHP? This little function will do exactly that. Simply supply a username, password and Tweet, and thanks to CURLs black magic your message will be Tweeted. You can also specify which format you would like the response in – either JSON or XML, with JSON being the default.

<? function tweet($username, $pword, $status, $format='json') {
$ch = curl_init(); // init curl
curl_setopt($ch, CURLOPT_URL, "http://twitter.com/statuses/update.".$format);
curl_setopt($ch, CURLOPT_POSTFIELDS, "status=$status");
curl_setopt($ch, CURLOPT_USERPWD, "$username:$pword");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$bf = curl_exec($ch); // execute curl call
curl_close($ch); // close curl handler
// Return true or false demending on results
return $bf;
} ?>

Using the PHP to Twitter function
echo tweet('TwitterUSERNAME','Password','Rocking the PHP-To-Twitter function by @brandoncorbin');

  Post to Twitter PHP Function (915 bytes, 41 hits)

No Responses

Write a comment
  1. Post to Twitter from PHP with this super simple function – http://bit.ly/bCUu2n

    wbcnews 8 February 2010 at 3:15 am Permalink
  2. Post to Twitter from PHP with this super simple function – http://bit.ly/bCUu2n

    brandoncorbin 8 February 2010 at 3:15 pm Permalink
  3. @bang590 底下还有一个错误:
    Fatal error: Call to undefined function curl_init() in www/t/lib/twitter.php on line 775

    yarkyang 9 February 2010 at 3:15 am Permalink
  4. @Showfom 你好,我在使用twiteseV1.3的时候提示lib/lib/twitter.php on line 832 Fatal error: Call to undefined function: json_decode() in 有有什么解决之法吗

    wyfusky 9 February 2010 at 3:15 pm Permalink
  5. Phooey. http://educon22.org = “Fatal error: Call to undefined function apc_fetch() in /var/mics/code/Plugins/functions/twitter.php line 9″ ?

    butwait 10 February 2010 at 3:16 am Permalink

Write a Comment

Commenter Gravatar