Amazon EC2環境でTwitterAPI叩いてて、このエラーでハマりました。
failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
リクエスト回数制限は超えてないし、
コマンドラインでwgetするとちゃんと取得できるし、
同じURLをブラウザやローカルPCから呼ぶとちゃんと値が戻るのに、
phpでfile_get_contents()するとエラーになる。。
で、いろいろ調べてたらapiwikiにこんなの見つけました。
Applications must have a meaningful and unique User Agent when using this method. A HTTP Referrer is expected but not required. Search traffic that does not include a User Agent will be rate limited to fewer API calls per hour than applications including a User Agent string.
Twitter Search API Method: search
ということで、
ini_set(‘user_agent’, ‘User-Agent: xxx’);
これを追加したら解決しましたよ。
ほっ
コメントを残す