Toast
Toast

Reputation: 657

Twitter4j: Download tweets after a certain tweet/point in time

I use twitter4j to get my timeline like this:

twitter.getHomeTimeline(new Paging(1,100));

How can I get the next 100 tweets? And in general, is it possible to specify two tweets or two points in time and get the tweets that were posted in between?

Upvotes: 3

Views: 3884

Answers (1)

Bill the Lizard
Bill the Lizard

Reputation: 406095

First, you can get the next 100 tweets in your timeline by specifying page 2 and calling getHomeTimeline again.

Paging paging = new Paging(2, 100);
List<Status> statuses = twitter.getHomeTimeline(paging);

You can also specify two tweets (by status id) using Paging to get the tweets that were posted in between using the sinceId and maxId methods.

since_id: returns elements which id are bigger than the specified id
max_id: returns elements which id are smaller than the specified id

For example:

Paging paging = new Paging(1, 10).sinceId(258347905419730944L)
                                   .maxId(258348815243960320L);
List<Status> statuses = twitter.getHomeTimeline(paging);

(I had about five tweets in my timeline between the two ids above. Just click on a tweet on the Twitter web interface and click on the Details link to be taken to the page for that tweet. Then you can copy the status ID from the URL.)

Upvotes: 10

Related Questions