且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Twitter API 总是说 400 Bad Request

更新时间:2023-01-03 18:42:16

您可能会受到速率限制

400 错误请求:请求无效.伴随的错误消息将解释原因.这是将返回的状态码限速期间.

400 Bad Request: The request was invalid. An accompanying error message will explain why. This is the status code will be returned during rate limiting.

未经身份验证的呼叫每小时 150 个请求(基于 IP 寻址)

每小时 350 次已验证调用请求(基于已验证用户调用)

350 requests per hour for authenticated calls (Based on the authenticated users calls)

您必须进行身份验证才能避免出现这些错误.

You have to authenticate to avoid these errors popping up.

并且在处理 twitter 时也请使用 cURL.我用file_get_contentsfopen 调用了twitter API,发现很不靠谱.你会时不时地受到打击.

And also please use cURL when dealing with twitter. I've used file_get_contents and fopen to call the twitter API, and found that it is very unreliable. You would get hit with that every now and then.

$ch = curl_init("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$username&count=$count");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$it = curl_exec($ch); //content stored in $it
curl_close($ch);