Twitter API-相同的光标错误


Twitter API - Same cursor error

从twitter的REST API我的用户获取/追随者函数。我在下面粘贴了一个代码片段。

我的问题是,大多数时候我都能成功获得追随者的id。但当一个用户拥有5000-6000多名粉丝时,我的结果就会出错。

当我从用户的个人资料页面查看时,我看到用户有5500名追随者,但当我运行以下代码时,大多数时候会有5500个id,但有时29994名追随者会出现在$ids变量中。现在我记录的结果有超过2900的追随者。我看到一些回复的请求有29994名粉丝,但我找不到答案。

在get-ids-cursor方法中,我错过了什么吗?谢谢

编辑:经过一些调试,我记录了"$cursor_archieve"参数,并发现:
*有时next_cursor和previous_cursor是相同的:

Array
(
    [0] => -1
    [1] => 1400573121087317741
    [2] => 1400573121087317741
    [3] => 1400573121087317741
    [4] => 1400573121087317741
    [5] => 1400573121087317741
    [6] => 1400573121087317741
)

所以在这种情况下,虽然用户有7100个追随者,但我只有5000个追随者

  • 有时光标顺序相同:

    数组

    [0]=>-1
    [1] =>1404335879106773348
    [2] =>1404341060469987526
    [3] =>1404338682006540390
    [4] =>1404341060469987526
    [5] =>1404335879106773348
    [6] =>1404338682006540390
    )

我的代码是这样的:

public function getIds($user = "someuser"){
    $tmhOAuth = new tmhOAuth(array( 'consumer_key'    => YOUR_CONSUMER_KEY, 
              'consumer_secret' => YOUR_CONSUMER_SECRET,
              'user_token'      => $atoken1, 'user_secret'     => $atoken2, ));
    $cursor = '-1';
    $ids = array();
    $cursor_archieve = array();
    while(true):
        $code=$tmhOAuth->request('GET', $tmhOAuth->url('1/followers/ids'),
                array('screen_name' => $user, 'cursor' => $cursor));
        if ($code == 200) {
            $responseData = json_decode($tmhOAuth->response['response'],true);
            $ids = array_merge($ids, $responseData['ids']);
            $cursor = $responseData['next_cursor_str'];
                    $cursor_archieve[] = $cursor;
        } else {
            return 0;
        }
        if ( $cursor == '0' || count($ids) >= 29000 ) {
            break;
        }
    endwhile;
    return $ids;
}

edit2:我应该设置"array_unique"来删除重复的id,还是如果previous_cursor=next cursor或任何其他选项,则不使用next curcursor?在每种情况下,用户都有5500-6500名追随者。所以,如果我只拿一个光标,我只能得到前5000个追随者。

原因是我的代码中存在程序错误。我在一周的调试会话后修复了它