我怎样才能获得最近一次检查的最新推文?

时间:2011-06-29 03:47:03

标签: php

我正在使用PHP和tweeter RSS来解析推文并尝试将推文存储在数据库中。

有没有办法,我可以只获取/解析最近的推文,而不是最后一次解析或检查?因为偶尔可能会有关于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;

}

1 个答案:

答案 0 :(得分:0)

你不能用rss做到这一点,但由于twitter想要move away from rss,你可以开始使用home_timeline api method。它支持since参数