Hace poco vi esta pequeña joya de código que permite tweetear (¿?) directamente desde código PHP.

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

La forma de utilizarlo no puede ser más sencilla

tweet('From PHP, yeah...', 'fabpot', 'Pa$$');

Muy útil hoy en día cuando muchas aplicaciones se conectan a Twitter para hacer actualizaciones automáticas.

Post original: Tweeting from PHP


Compártelo:
  • Print this article!
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Ping.fm
  • RSS
  • Twitter