Twitter流最新推文不起作用

时间:2011-01-31 06:30:42

标签: php twitter twitter-oauth

我试图在网页上显示最新的推文,但我不确定如何做到这一点,因为我对twitter api很新,但这是我到目前为止所做的。

function my_streaming_callback($data, $length, $metrics) {
  echo $data;
}

require '../tmhOAuth.php';
$tmhOAuth = new tmhOAuth(array(
  'consumer_key'    => 'key',
  'consumer_secret' => 'secret',
  'user_token'      => 'token',
  'user_secret'     => 'secret',
));

$method = 'http://stream.twitter.com/1/statuses//show/:id.json';
//not sure where I am supposed to get the :id from?

$params = array(
  //not sure what to put here, I would like to display the last 5 tweets
);

$tmhOAuth->streaming_request('POST', $method, $params, 'my_streaming_callback');
$tmhOAuth->pr($tmhOAuth);

我正在使用此https://github.com/themattharris/tmhOAuth进行身份验证,然后与twitter api进行交互,但我发现它非常令人困惑,因为所有这些对我来说都是新的。

所以基本上我只是想尝试获取最新的推文,任何帮助都会非常感激,因为我需要尽快完成这项工作,而不是提前完成! :)

2 个答案:

答案 0 :(得分:1)

Stream API仅返回您在连接后 后发布的推文。要获取以前的推文,您需要使用常规REST API方法:http://dev.twitter.com/doc/get/statuses/show/:id

$tmhOAuth->request('GET', $tmhOAuth->url('1/statuses/show/$id'));
$tmhOAuth->pr(json_decode($tmhOAuth->response['response']));

其中$id是用户的ID。

答案 1 :(得分:0)

如果您希望可以使用THIS漂亮的jQuery插件。它根据您的需要做一些事情。有关更多信息,请访问http://tweet.seaofclouds.com/