使用twitter搜索api错误file_get_contents

时间:2012-11-08 08:44:13

标签: json search curl twitter file-get-contents

我遇到以下问题:此脚本运行时

    $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)

但它很奇怪,因为它一直在工作! 你能帮助我吗? 添加...我试图以这种方式使用CURL

$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); 

但是调用返回了此消息 “错误”:“你的速度有限。加强你的平静。”}这似乎很荒谬,因为我之前没有提出任何要求。

1 个答案:

答案 0 :(得分:0)

我发现到处都是这种情况下的最佳做法是使用CURL。 我不知道为什么然后我尝试用 urlencode 传递参数('obama'),似乎是这种警告的语法(以前不正确)。