开发者

Twitter stream latest tweets not working

开发者 https://www.devze.com 2023-02-08 03:05 出处:网络
I am trying to show the latest tweets on a webpage, but I am unsure of how to do it as I am very new开发者_JAVA百科 to the twitter api, but here is what I have thus far.

I am trying to show the latest tweets on a webpage, but I am unsure of how to do it as I am very new开发者_JAVA百科 to the twitter api, but here is what I have thus far.

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);

I am using this https://github.com/themattharris/tmhOAuth to authenticate, and then interface with the twitter api, but I am finding it very confusing as all of this is very new to me.

So basically I would just like to try and get the latest tweets, any help would be GREATLY appreciated, as I need to get this done ASAP, thanx in advance! :)


Stream API returns you only the tweets posted after you connected. To get previous tweets you need to use general REST API method: 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']));

where $id is the user's id.


If you wish you can use THIS beautiful jQuery plugin. It do the some thing as you require. For more information visit http://tweet.seaofclouds.com/

0

精彩评论

暂无评论...
验证码 换一张
取 消