直到几周前,下面的代码还可以很好地抓取我最后的三条推文并将它们显示在我的网站上。现在它不工作了。我浏览了 Twitter 的留言板,看看是否有什么变化无济于事。
有谁知道如何使用 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>