问题
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