What is the most effective way to get a list of followers using Twitter4j?

谁说胖子不能爱 提交于 2020-01-02 10:22:23

问题


I am using the Twitter4j library and I am trying to get the followers list of the authenticated user.

I am doing the following:

IDs followersIds = mTwitter.getFollowersIDs(-1);
long [] ids = followersIds.getIDs();

List<User> followers = new ArrayList<User>();
for(int i = 0; i < ids.length; i++) {
   followers.add(mTwitter.showUser(ids[i]));
}

Although this may work, it's far from being effective since it sends one request for each follower. Besides the slowness of this method, I ultimately get the following error:

error - Rate limit exceeded. Clients may not make more than 350 requests per hour.

Anyone knows any better method to do this? (I spent some time on the documentation but couldn't find any).

Thanks!


回答1:


There is a lookupUsers(long[] ids) method in UserMethods you should use for this purpose. You pass it an array of at most 100 user ids (per request) and get all extended information returned.

Bear in mind you might want to use the async version of this method, as you probably don't want to do the requests on the UI thread.




回答2:


There is method

PagableResponseList<User> twitter4j.api.FriendsFollowersResources.getFollowersList(long arg0, long arg1) throws TwitterException


来源:https://stackoverflow.com/questions/8659209/what-is-the-most-effective-way-to-get-a-list-of-followers-using-twitter4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!