2013-02-01 21 views
0

警告我有一個網站Twitter的飼料,並一直在努力沒問題最後5分鐘,但是突然間它已經停止,並拋出這個錯誤:如何解決的file_get_contents Twitter並

Warning: file_get_contents(http://api.twitter.com/1/statuses/user_timeline/xxx.json) 

[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /home/fhlinux009/t/xxx.co.uk/user/htdocs/wp-content/themes/xxx/homepageTest.php on line 100 

用xxx代替敏感數據。

的代碼是這樣的:

<?php 
    $username='xxx'; // set user name 
    $format='json'; // set format 
    $tweet=json_decode(file_get_contents("http://api.twitter.com/1/statuses/ 
    user_timeline/{$username}.{$format}")); // get tweets 
    //and decode them into a variable 
?> 

<div id="sliderId"> 
    <ul> 
    <li class="current"><?php echo $tweet[0]->text; ?></li> 
    <li><?php echo $tweet[1]->text; ?></li> 
    <li><?php echo $tweet[2]->text; ?></li> 
    </ul> 
</div> 

我不得不使用這種方法採用了滑蓋的工作。我不確定它爲什麼停止工作。

更新:如果請求耗盡服務器,是否可以一次將file_get_contents的結果緩存大約15/30分鐘?

+0

仔細檢查TWITTER API是否仍然支持您使用的這種方法。 –

+0

好的,我將爲此進行瀏覽。正如我所說的那樣,儘管:/。請看看他們的API –

+0

你想打什麼類型的網址?你能告訴我的網址 – rohitarora

回答

0
  1. 檢查url,在瀏覽器中手動執行它。
  2. 如果url在瀏覽器中啓用allow_url_fopen設置在php ini並重新啓動服務器。
+0

嗨,感謝您的評論我會做到這一點,但我現在認爲問題是請求已耗盡服務器。我可以緩存結果嗎? –