2013-07-02 120 views
0

直到幾個星期前,下面的代碼很好地抓住了我的最後三條推文,並將它們顯示在我的網站上。現在它不工作。我已經瀏覽了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> 
+0

那麼現在不工作?您是否嘗試過調試代碼以查看它失敗的位置? –

+0

https://github.com/andrewbiggart/latest-tweets-php-o-auth/blob/master/tweets.php –

回答

2

您正在使用的Twitter API 1.0已在幾周前關閉。

在API 1.1點擊此處閱讀起來:https://dev.twitter.com/docs/api

有兩種使用新的API工作,包括mine PHP庫萬噸。

+0

謝謝Tim。我不是一個開發人員。你有沒有任何工作的例子? – zer0ruth

+0

'working'需要我將我的祕密憑據添加到代碼中。看一下示例文件夾中的示例,沒有刪除祕密。 – Tim

+0

我們不希望你給出你的祕密憑證。我有消費者機密,授權令牌,消費者密鑰,請求令牌等,我可以將它們插入到您的某個庫中以使其正常工作嗎? – zer0ruth