Обновляем статус в Twitter из PHP

Небольшая функция, позволяющая обновить Ваш статус в Twitter из 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;
}

Использовать так:

if (tweet('Hello, Twitter!', 'user', 'password'))
 echo "Статус обновлен";
else
 echo "Ункноун Егог!";

Поблагодарить автора

3 Responses to Обновляем статус в Twitter из PHP

  1. Код уже год как не рабочий. С августа они сменили принцип авторизации. Авторизация теперь только по oAuth

Оставить комментарий

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>