开发者

How to be sure my web app gets the next tweet after specified tweet

I am creating a webapp that relies on following a status timeline from twitter in php

I am making a request to the twitter using the following API call:

$since_id is equal to a stored id based on the last parsed tweet.

$req开发者_StackOverflow社区_url = 'http://twitter.com/statuses/friends_timeline.xml?count=20&page=1&since_id='.$since_id;

I have noticed that if more than 20 tweets come through since the last call i'll get the most recent 20 tweets since the last call and in turn missing those between the $since_id and the current 20.

example:

  1. at 0800 the last tweet parsed was 70001
  2. 50 tweets are made in the 10 min window since the last API call
  3. at 0810 i call to the API to get tweets since 70001
  4. it returns tweets 70031 - 70051

which causes me to miss 70002-70030

Now to the quest: Is there a way to know how many tweets have been made since the last call? If so, is there a way to make sure when I call the API that I am getting the next tweet in line and not the most recent tweets made?

language: PHP5 using: Twitter REST API


you can set the since_id parameter to the last seen tweet and specify a count of 200. then retrieve the older ones by specifying max_id.

$startId = [last tweet_id]
$tweets = "twitter.com/statuses/friends_timeline.xml?since_id=${istartId}" .
  "&count=200"

while (count($tweets)) {
   insert $tweets into table on duplicate key update none
   $maxId = $tweets[count($tweets) - 1]['id'];
   if ($maxId <= $startId) {
     break;
   }
   $tweets = "twitter.com/statuses/friends_timeline.xml?max_id=${maxId}" .
     "&count=200"
}

there doesn't appear to be a way to begin paginating at a particular id. in the api, you always start with the most recent entries and work your way back in time to the last seen id.

it's possible to search within a date range using the search atom and the operators since,until, and from:

http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-search

but indeed, it's still sorted by time desc, so you would need to scroll back in any case.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜