Search code examples
javatwittertwitter4j

finding twitter4j retweet rate limit


I would like to know how to find in java a rate limit for specific function in twitter4j

twitter.retweetStatus(lstatusId);

I would like to know how to check if im passing the rate limit for retweeting.


Solution

  • You can add following piece of code to check for rate limit status, you would need to provide for specific url, for example if you are fetching "statuses/retweets_of_me" then your url-to-get-rate-limit-status-of would be "statuses/retweets_of_me"

    You would need to find mapping to Rest API url for each of your streaming API call and use that url to get the rate limit status.

    if (twitter.getRateLimitStatus().get(<<url-to-get-rate-limit-status-of>>).getRemaining() == 0) {
            System.out.println("Adding wait of - " + twitter.getRateLimitStatus().get(<<url-to-get-rate-limit-status-of>>).getSecondsUntilReset() + " seconds");
            Thread.sleep(twitter.getRateLimitStatus().get(<<url-to-get-rate-limit-status-of>>).getSecondsUntilReset()*1000);
        }
    

    Hope this helps.