直到幾個星期前,下面的代碼很好地抓住了我的最後三條推文,並將它們顯示在我的網站上。現在它不工作。我已經瀏覽了Twitter的留言板,看看是否有變化無濟於事。在我的網站上顯示Twitter Feed
有誰知道如何有效地顯示您使用php的網站上的最新推文?
我原來的代碼在這裏。就像我說的,這個工作,直到幾個星期前:
$twitterUsername = "myUsername";
$amountToShow = 3;
$twitterRssFeedUrl = 'https://api.twitter.com/1/statuses/user_timeline.rss?screen_name='.$twitterUsername.'&count='.$amountToShow;
$twitterPosts = false;
$xml = @simplexml_load_file($twitterRssFeedUrl);
if(is_object($xml)){
foreach($xml->channel->item as $twit){
if(is_array($twitterPosts) && count($twitterPosts)==$amountToShow){
break;
}
$d['title'] = stripslashes(htmlentities($twit->title,ENT_QUOTES,'UTF-8'));
$description = stripslashes(htmlentities($twit->description,ENT_QUOTES,'UTF-8'));
if(strtolower(substr($description,0,strlen($twitterUsername))) == strtolower($twitterUsername)){
$description = substr($description,strlen($twitterUsername)+1);
}
$d['description'] = $description;
$d['pubdate'] = strtotime($twit->pubDate);
$d['guid'] = stripslashes(htmlentities($twit->guid,ENT_QUOTES,'UTF-8'));
$d['link'] = stripslashes(htmlentities($twit->link,ENT_QUOTES,'UTF-8'));
$twitterPosts[]=$d;
}
}else{
die('Can`t fetch the feed you requested');
}
,然後將其變成了在HTML像這樣:
<dl class="twitter">
<dt>Twitter Feed</dt>
<?php
if(is_array($twitterPosts)){
echo '';
foreach($twitterPosts as $post){
$data = hyperlinks($post['description']);
$data = twitter_users($data);
echo '<dd>'.$data.'. ';
echo '<a href="'.$post['link'].'" class="timestamp">Posted '.time2str(date($post['pubdate'])).'</a></dd>';
}
echo '';
}else{
echo 'No Twitter posts have been made';//Error message
}
?>
<dd>
那麼現在不工作?您是否嘗試過調試代碼以查看它失敗的位置? –
https://github.com/andrewbiggart/latest-tweets-php-o-auth/blob/master/tweets.php –