2011-06-29 17 views
0

我正在使用PHP和高音揚聲器RSS來分析推文並嘗試將推文存儲在數據庫中。我怎樣才能得到比上次檢查最近的推文?

有沒有什麼辦法,我只能得到/解析最近的推文比上次分析或檢查?因爲時不時的微博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; 

}

+0

從數據庫中檢索最新的行並將其與每個RSS源項目比較,直到你得到一個較舊的,比你已經有了? – zerkms

+0

這是我現在正在做的,但我的客戶說,有沒有辦法檢查最近的鳴叫 – logudotcom

+0

沒有rss接受任何參數? – zerkms

回答

0

你不能做到這一點與RSS,但由於Twitter的希望move away from rss您可以開始使用home_timeline api method。它支持since參數

+0

看來,我使用的是同樣的方法。我如何修改以獲取最近的推文? – logudotcom

+0

@logudotcom:添加'自''參數值等於您檢索的最新推文。像'?since = 12345678' – zerkms

+0

還有一個問題,這個特殊的「since」,我如何更新或獲取上次檢索或過程的值? – logudotcom