I'm trying to make a method public void limit()
that checks the rate limit and sleeps however long it is until the reset if it is being rate limited. I cannot, however, figure out how to make a RateLimitStatus. I have tried:
RateLimitStatus status = twitter.getRateLimitStatus();
but it doesn't actually return a RateLimitStatus... Quite frankly, I'm not sure what the point of that is. Anyway, if anyone is aware of how to get a RateLimitStatus, their help would be much appreciated as currently my project is capable of crashing due to rate limits and I'd like to change this.
Thanks in advance!
The new Twitter API has a rate limit status per resource “family”, so twitter.getRateLimitStatus()
returns a mapping between families/endpoints and rate limit statuses, e.g.:
RateLimitStatus status = twitter.getRateLimitStatus().get("/users/search");
// Better: specify the family
RateLimitStatus status2 = twitter.getRateLimitStatus("users").get("/users/search");
So, you could write a method public void limit(String endpoint)
, which would check the proper rate limit status.
public void limit(String endpoint) {
String family = endpoint.split("/", 3)[1];
RateLimitStatus status = twitter.getRateLimitStatus(family).get(endpoint);
// do what you want…
}
You’ll then call it with .limit("/users/search")
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With