twitter4j中的getFollowersList不会检索关注者

时间:2013-05-17 16:19:28

标签: java twitter twitter4j

这是我的代码:

int favouritesCount = user.getFavouritesCount();
int followersCount = user.getFollowersCount();
int friendsCount = user.getFriendsCount();
long userId = user.getId();
System.out.println("FavouritesCount: " + favouritesCount + ", followersCount: " + followersCount + ", friendsCount: " + friendsCount);
ArrayList<User> followers = new ArrayList<User>();
long nextCursor = 0;
do {
    PagableResponseList<User> usersResponse = twitter.getFollowersList(user.getScreenName(), nextCursor);
    System.out.println("size() of first iteration:" + usersResponse.size());
    nextCursor = usersResponse.getNextCursor();
    followers.addAll(usersResponse);
} while ( nextCursor > 0);

System.out.println( followers.size() > 0 ? "Getting followers:" : "No followers.");

for ( User user : followers) {
    System.out.println(user.getScreenName() + ", id: " + user.getId());
}

这是我得到的输出:

FavouritesCount: 0, followersCount: 1, friendsCount: 1
size() of first iteration:0
No followers.

我在这里做错了什么?用户通过OAuth进行身份验证,一切都很好,除了这部分代码根本不起作用。跟随者和朋友的数量是正确的,但我有看到粉丝的问题。

请帮忙!

最佳, d

1 个答案:

答案 0 :(得分:5)

我已经解决了这个问题。实际上,错误在于以下几行:

long nextCursor = 0;

应该设置

long nextCursor = -1;

作为文档非常明确地“说”:link

再次感谢!