开发者

How can I get the recent tweets than last time checked?

I am using PHP and tweeter RSS to parse the开发者_运维百科 tweets and trying to store the tweets in the database.

Is there any way, I can get/parse only the recent tweets than the last time parsed OR checked? because every now and then there may be tweets updates on tweeter RSS.

function fetch_rss_tweets($username, $maxtweets) {
 //Using simplexml to load URL
 $tweets = simplexml_load_file("http://twitter.com/statuses/user_timeline/" . $username . ".rss");


 $tweet_array = array();  //Initialize empty array to store tweets
 foreach ( $tweets->channel->item as $tweet ) { 

    /*  print '<pre>';
        print_r ($tweet);
        print '</pre>';*/

      //Loop to limitate nr of tweets.
      if ($maxtweets == 0) {
           break;
      } else {
           $twit = $tweet->description;  //Fetch the tweet itself

           //Remove the preceding 'username: '
           $twit = substr(strstr($twit, ': '), 2, strlen($twit));

           // Convert URLs into hyperlinks
         //  $twit = preg_replace("/(http:\/\/)(.*?)\/([\w\.\/\&\=\?\-\,\:\;\#\_\~\%\+]*)/", "<a href=\"\\0\">\\0</a>", $twit);

           // Convert usernames (@) into links 
           $twit = preg_replace("(@([a-zA-Z0-9\_]+))", "<a href=\"http://www.twitter.com/\\1\">\\0</a>", $twit);

           // Convert hash tags (#) to links 
           $twit = preg_replace('/(^|\s)#(\w+)/', '\1<a href="http://search.twitter.com/search?q=%23\2">#\2</a>', $twit);

           //Specifically for non-English tweets, converts UTF-8 into ISO-8859-1
           $twit = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $twit);


           //Store tweet and time into the array
           $tweet_item = array(
                 'desc' => $twit,                                        
           );
           array_push($tweet_array, $tweet_item);

           $maxtweets--;
      }
 }
 //Return array
 return $tweet_array;

}


You cannot do that with rss, but since twitter wants to move away from rss you may start using home_timeline api method. It supports since parameter

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜