Example usage for twitter4j RateLimitStatus getLimit

List of usage examples for twitter4j RateLimitStatus getLimit

Introduction

In this page you can find the example usage for twitter4j RateLimitStatus getLimit.

Prototype

int getLimit();

Source Link

Document

Returns the current limit in effect
This value is identical to the "X-Rate-Limit-Limit" response header.

Usage

From source file:tweetcrawling.TweetCrawler.java

public void rateLimitHandler(TwitterConfiguration tc_, String endpoint)
        throws TwitterException, InterruptedException {
    Map<String, RateLimitStatus> rateLimitStatus = tc_.getTwitter().getRateLimitStatus();
    RateLimitStatus appRateLimit = rateLimitStatus.get(endpoint);

    System.out.printf(endpoint + ": You have %d calls remaining out of %d, Limit resets in %d seconds\n",
            appRateLimit.getRemaining(), appRateLimit.getLimit(), appRateLimit.getSecondsUntilReset()); // For debug purposes

    if (appRateLimit.getRemaining() < 10) {
        System.out.println("Sleeping for " + appRateLimit.getSecondsUntilReset() + " seconds due to " + endpoint
                + " rate limit."); // For debug purposes
        Thread.sleep((appRateLimit.getSecondsUntilReset() + 2) * 1001);
    }//from  w w w.  ja v  a2s.  c om
}

From source file:twitter4j.examples.account.GetRateLimitStatus.java

License:Apache License

/**
 * Usage: java twitter4j.examples.account.GetRateLimitStatus
 *
 * @param args message//from  w  w  w .ja v a2 s  . co  m
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus();
        for (String endpoint : rateLimitStatus.keySet()) {
            RateLimitStatus status = rateLimitStatus.get(endpoint);
            System.out.println("Endpoint: " + endpoint);
            System.out.println(" Limit: " + status.getLimit());
            System.out.println(" Remaining: " + status.getRemaining());
            System.out.println(" ResetTimeInSeconds: " + status.getResetTimeInSeconds());
            System.out.println(" SecondsUntilReset: " + status.getSecondsUntilReset());
        }
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get rate limit status: " + te.getMessage());
        System.exit(-1);
    }
}