0

直到几周前,下面的代码还可以很好地抓取我最后的三条推文并将它们显示在我的网站上。现在它不工作了。我浏览了 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>
4

2 回答 2

2

Twitter API 1.0 that you're using has been switched off, as of a few weeks ago.

Read up on the API 1.1 here: https://dev.twitter.com/docs/api

There are tonnes of PHP libraries for working with the new API, including mine.

于 2013-07-02T19:25:10.640 回答
0

Twitter REST API v1 不再活动。请迁移到 API v1.1。https://dev.twitter.com/docs/api/1.1/overview

于 2013-07-02T19:24:39.887 回答