2012-11-08 106 views
0

錯誤的file_get_contents我有以下問題:當運行此腳本與Twitter的搜索API

$url = 'http://search.twitter.com/search.json?q=obama'; 
    $tw = file_get_contents($url,0,null,null); 

我收到此消息。

Warning (2): file_get_contents(http://search.twitter.com/search.json?q=obama) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 420 Client Error (420) 

但這很奇怪,因爲它一直在工作! 你能幫我嗎? 添加...我試圖使用捲曲這樣

$url = 'http://search.twitter.com/search.json?q=obama'; 
$c = curl_init(); 
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($c, CURLOPT_URL, $url); 
$contents = curl_exec($c); 
echo $contents; 
curl_close($c); 

但調用返回此消息 「錯誤」:「你已經速率限制增強你的​​平靜。」},它似乎荒謬,因爲我沒有以前沒有提出任何要求。

回答

0

我隨處可見,在這種情況下,最好的做法是使用捲曲。 我不知道爲什麼,但後來我試圖與進行urlencode傳遞參數(「奧巴馬」),它似乎是語法(以前不正確的)主此警告的原因。