从Twitter用户时间线请求收到非常慢的响应,Twitter API是否缓慢?

时间:2014-02-08 08:11:08

标签: api rest drupal twitter

我正在从多个帐户(大约20个)中检索推文并在页面上显示这些推文。请求非常慢,我的页面需要一到两分钟才能加载。我正在使用twitteroauth库(PHP)。如果我减少帐户数量,加载时间会减少。

这是函数

//twitter credentials and connection
$consumer_key = variable_get('tw_consumer_key', 'xxxxxxxxxxx'); //consumer key
$consumer_secret = variable_get('tw_consumer_secret', 'xxxxxxx'); // consumer secret
$oauth_token = variable_get('tw_access_token', 'xxxxxxxxxxxx'); //oAuth Token
$oauth_token_secret = variable_get('tw_access_token_secret', 'xxxxxxxxxx'); //oAuth Token Secret

$connection = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
$connection->host = "https://api.twitter.com/1.1/";


//Retrieve feeds now
foreach ($twitter_accounts as $account_twitter) {
    if (!empty($account_twitter['lien'])) {
        $page_url = $account_twitter['lien'];
        $twitter_name = $account_twitter['compte'];

        $query = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=' . $twitter_name . '&exclude_replies=true&include_rts=true&include_entities=true';

        $content = $connection->get($query);

        if (sizeof($content) > 0 && empty($content->errors)) {
            $tw_tweets['posts'] = $content;
            $tw_tweets['url'] = $page_url;
            $twitter_feeds[] = $tw_tweets;
        }//end if sizeof
        else {
            if (!empty($content->errors)) {
                $error = '';
                $error = (isset($content->errors[0]->message)) ? $content->errors[0]->message : '';
                $error .= (isset($content->errors[0]->code)) ? ' code' . $content->errors[0]->code : '';
                watchdog('ffbb_hubsocial', 'Twitter Account ' . $account_twitter['compte'] . ' failed to return results :' . $error);
            }
        }
    }
}

API速度慢吗? 任何人都知道问题是否与推特有关?

1 个答案:

答案 0 :(得分:0)

重复问题:Why are the Twitter api calls so slow?

如上面的答案所述,请尝试在浏览器中测试网址,看看需要多长时间。因此,您将能够看到问题是在您身边还是由于Twitter。