【问题标题】:Twitter stream latest tweets not workingTwitter流最新推文不起作用
【发布时间】:2011-01-31 15:37:13
【问题描述】:

我正在尝试在网页上显示最新的推文,但我不确定该怎么做,因为我对 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 进行交互,但我发现它非常令人困惑,因为所有这些对我来说都是非常新的。

所以基本上我只想尝试获取最新的推文,任何帮助将不胜感激,因为我需要尽快完成这项工作,谢谢! :)

【问题讨论】:

    标签: php twitter twitter-oauth


    【解决方案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。

    【讨论】:

    • 好的,我该怎么做呢?我不确定如何获得:id
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2013-04-28
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-18
      • 2013-05-29
      • 2012-04-18
      • 1970-01-01
      相关资源
      最近更新 更多