Project to handle twitter api rate limits.
Using RateLimitStatus object and calculates average time per api call and calls Thread.sleep() for calculated time.
You can update default delay for api calls in ApiProcessType enumeration.
to use in your gradle project add this into your settings.gradle and build.gradle files respectively:
settings.gradle:
sourceControl {
gitRepository("https://github.com/akadir/rate-limit-handler.git") {
producesModule("com.kadir.twitterbots.commons:rate-limit-handler")
}
}
build.gradle:
dependencies {
implementation 'com.kadir.twitterbots.commons:rate-limit-handler:1.0'
}
And then call `RateLimitHandler.handle() method after your api calls:
ex-1:
Status updatedStatus = twitter.updateStatus(textToTweet);
RateLimitHandler.handle(twitter.hashCode(), updatedStatus.getRateLimitStatus(), ApiProcessType.UPDATE_STATUS);
ex-2:
Paging paging = new Paging(1, 100);
ResponseList<Status> statuses;
statuses = twitter.getUserTimeline(twitter.getId(), paging);
RateLimitHandler.handle(twitter.getId(), statuses.getRateLimitStatus(), ApiProcessType.GET_USER_TIMELINE);