Search code examples
javatwittertweets

Twitter, get all Tweets of the last 24 hours


I'm working on an application that needs to show all tweets of a certain user made in the last 24 hours. Is there a convenient way using the REST-API? I would like to avoid some kind of caching mechanism using the timeline. Thank you :)


Solution

  • The only thing you can do with the Twitter REST API is something like this :

    Timeline resTimeline = downloadTimeline();
    Tweet lastTweet = resTimeline.get(resTimeline.size() - 1);
    
    while (lastTweet is younger than 24 hours) {
        TweetID lastTweetID = lastTweet.id;
        Timeline bufferTimeline = downloadTimeline(max_id = lastTweetID);
        resTimeline.addAll(bufferTimeline);
        lastTweet = resTimeline.get(resTimeline.size() - 1);
    }
    
    return resTimeline;