【问题标题】:Error file_get_contents with twitter search apitwitter 搜索 api 错误 file_get_contents
【发布时间】:2012-10-28 10:27:35
【问题描述】:

我有以下问题:当这个脚本运行时

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

但是调用返回了这条消息 "error":"你被限速了。增强你的冷静。"}这似乎很荒谬,因为我之前没有提出任何要求。

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-07-09
      • 2016-07-26
      • 2011-04-29
      • 1970-01-01
      • 2021-08-16
      • 2020-06-05
      • 1970-01-01
      • 1970-01-01
      • 2019-03-13
      相关资源
      最近更新 更多