Twitter让关注者/ ids光标无效

时间:2014-04-23 21:53:13

标签: twitter

我正在尝试获取Twitter用户的完整关注者ID列表。这位用户拥有170,000多名粉丝。我正在使用代码鸟库。这是代码:

\Codebird\Codebird::setConsumerKey(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
$cb = \Codebird\Codebird::getInstance();
$cb->setToken(OAUTH_TOKEN, OAUTH_SECRET);
$cb->setReturnFormat(CODEBIRD_RETURNFORMAT_ARRAY);
$next_cursor = -1;

while ($next_cursor) {  
    $results = $cb->followers_ids("screen_name=some_tw_name","count=5000","cursor=$next_cursor");
    $next_cursor = $results['next_cursor_str'];
}

第一个调用返回5000个ID,因为它应该是。后续调用(通过while循环)返回5000个ID,但它们几乎与前一个调用完全相同(每个新调用我得到1到大约10个新闻ID,其余部分与之前相同)。

其他人遇到此问题?分辨率?

1 个答案:

答案 0 :(得分:0)

我认为问题在于您并未真正合并每个请求的结果。所以你可以这样做:

function getFollowers(){
    $next_cursor = -1; 
    $output = array();
    while ($next_cursor) {  
        $results = $cb->followers_ids(array("screen_name"=>"some_tw_name","count"=>5000,"cursor"=>$next_cursor));
        if(!isset($results['errors'])){
            foreach($results['ids'] as $id){
                $output[]=$id;
                }
            }
        $next_cursor = $results['next_cursor_str'];
        }
    return $output;
    }

注意:我还将参数表示法更改为数组而不是字符串。