If you want to run a loop at the limit, you could do something like this:
Twitter jtwit = ...;
while(true) {
try {
// Call Twitter methods, e.g.
jtwit.getUserTimeline();
} catch (TwitterException e) { /* handle exception or just continue? */ }
// pause as needed
if (jtwit.isRateLimited(KRequestType.NORMAL, 1)) {
RateLimit rateLimit = jtwit.getRateLimit(KRequestType.NORMAL);
rateLimit.waitForReset();
}
}
waitForReset() is a new method in the latest version which calls
Thread.sleep with the time until the reset date.
I've also improved the java-doc for the RateLimit methods. The
RateLimit object is created using the headers from the previous
Twitter call. So calling getRateLimit() is quick (it doesn't require a
fresh call to Twitter), but the RateLimit object isn't available until
after you make a call of the right type to Twitter. Also, be aware
that there are different rate-limits for the different Twitter
methods. For example, you can be OK for search() but not for show().
> Right now I'm going in to a wait state between api calls, and I know
> there is a better way.
When we need to make extensive use of Twitter at http://sodash.com, I
harness several Twitter accounts, and use the rate limit to switch
between them.
Best regards,
- Daniel
--
--------------------------------------------------
Daniel Winterstein
Edinburgh
http://winterwell.com http://soda.sh
No - it's set by Twitter. You can apply for an upgrade, but they
rarely grant them these days.
> Using multiple accounts for rate limits is an interesting approach. If I use
> one account for a status search, would it be valid to then re-tweet that
> status using a different twitter account, or would that confuse some
> internal id? Just curious. :)
You can certainly search from one Twitter account, and then post
responses from another.
But posting isn't rate-limited, so there'd be no need to do that.
Best regards,
- Daniel