LoginSignup
2
2

More than 5 years have passed since last update.

Twitter 1.1 search API

Posted at

Twitter 1.1 APIでハマったのでメモ。

twitterAPI呼出用メソッド

public function api($cmd, $params = array()) {
    $url = "https://api.twitter.com/1.1/" . $cmd;
    try {
        $this->_oauth->setToken("oauth_token", "oauth_token_secret");
        $this->_oauth->fetch($url, $params, OAUTH_HTTP_METHOD_GET);
        $json = json_decode($this->_oauth->getLastResponse(), true);
    } catch (Exception $e) {
    }
    return $json;
}

間違い

$this->api("/search/tweets.json", array("q" => "test"));

$url が https://api.twitter.com/1.1//search/tweets.json の場合
なぜか、検索結果のデータ取得可能。
が、APIのrate limitは減らない。最大15回。(15分で解除)
エラー時(16回目以降)のhttp Response
Invalid auth/bad request (got a 429, expected HTTP/1.1 20X or a redirect)

正解

$this->api("search/tweets.json", array("q" => "test"));

$url が https://api.twitter.com/1.1/search/tweets.json の場合
もちろん、検索結果のデータ取得可能。
ちゃんと、APIのrate limitも減る。最大180回。(15分で解除)

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2