PHP: Enviar post a Twitter

Author: Adrià Cidre  |  Category: PHP

Os dejo una función para enviar mensajes a Twitter desde 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;
}

One Response to “PHP: Enviar post a Twitter”

  1. Hugo Says:

    porque si quiero enviar otro mensaje no me deja?

Leave a Reply