Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter4j getFollowersIDs cursor issue

I'm new to this Twitter4j library. I am trying to store all the followers ID's of a user with given userID. I am using something like the following:

IDs ids;
long cursor = -1;

do{ 
    ids = twitter.getFollowersIDs(userName, cursor);
    for (long id : ids.getIDs()) {
        // Store this id...
}
while ((cursor = ids.getNextCursor()) != 0);

After a while, I get the error Rate limit exceeded, it's OK. However, I don't know how to continue to store follower's IDs of the given userID when my rate limit problem fixed in the future?

PS: The userIDs whom I'm tryin to store follower's ID's have more than 3 million followers. It's why I need to continue from the place where I left.

like image 905
Sait Avatar asked Oct 21 '22 07:10

Sait


1 Answers

The API resource GET followers/ids - which is what getFollowersIDs() is under the hood - is subject to rate-limiting.

According to the rate limiting documentation for this resource, you can perform 15 requests in a 'rate limit window' with windows being 15 minutes in duration. So in essence, every 15 minutes you can make another 15 requests.

It seems that in order for you to fetch the 3m followers' IDs you will need to throttle your requests somehow, e.g. only make a request per minute etc...

Note that rate-limiting is per-resource and some limits are more generous than others. You can find out more about how the rate-limiting works here.

like image 87
Jonathan Avatar answered Oct 24 '22 10:10

Jonathan