TwitterAPIExchange 突然停止工作

TwitterAPIExchange suddenly stops working

所以我正在制作一个 Twitter 获取网站,其中来自特定主题标签的所有推文都将使用 ajax 实时获取。一切正常,我想,直到它突然停止工作。如果我再等 3 分钟左右,它就会再次开始工作。 PHP 给我错误,例如

Notice: Trying to get property of non-object...

我的代码是运行:

require_once '../lib/TwitterAPIExchange.php';

$settings = array(
    'oauth_access_token' => "...",
    'oauth_access_token_secret' => "...",
    'consumer_key' => "...",
    'consumer_secret' => "..."
);

$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=#hashtag&result_type=recent';
$requestMethod = 'GET';

$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
                             ->buildOauth($url, $requestMethod)
                             ->performRequest();

foreach(json_decode($response) as $result){
    foreach($result as $post){
        echo '<div class="post"><div class="header"><img src="'.$post->user->profile_image_url.'"><p class="user">'.$post->user->name.'</p></div><div class="text">'.$post->text.'</div></div>';
    }
    break;
}

我在@Uwe Allner 的帮助下弄明白了。原来 Twitter API 有一个叫做 API 速率限制的东西。因此,正如您可能猜到的那样,他们限制了每 x 次的请求量。在 "Search" 下,我注意到他们将限制设置为每 15 分钟 180 个查询。所以我可以每 5 秒查询一次。

180/15 = 12
60/12 = 5