2012-11-08 107 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传递参数(“奥巴马”),它似乎是语法(以前不正确的)主此警告的原因。