Search code examples
twittertwitter4jtwitter-streaming-api

Get user data by using Twitter Streaming API, Twitter Rest API


I do some analysis on twitter users features like number of following , number of retweet, number of friend , etc I have all my information from Twitter Rest API But there is an Rate Limit Exceeded error occurred when I tried to retrieve all data can I have all these data from Twitter Streaming API , if I can , how I can you it? If not what Is the Solution?

Thanks for Help


Solution

  • On each response you can call getRateLimitStatus() to get a RateLimitStatus and if remaining calls is 0, sleep the thread till time limit is over.

    do {
        TwitterResponse response = twitter.getFollowersIDs(userId, cursor);
        RateLimitStatus status = response.getRateLimitStatus();
        if(status.getRemaining() == 0) {
            try {
                Thread.sleep(status.getSecondsUntilReset() * 1000);
            }
            catch(InterruptedException e) {
                // ...
            }
        }
    } while(cursor > 0);
    

    Twitter API update limits error 403