Reputation: 2144
We are using twitter4j userTimeLine for getting tweets from particular user. How do I use maxId and How do I fetch tweets from the last fetch of tweets???
My source code as follows,
public List<Status> userTimeLine(String keyWord, int page, int count) {
log.info("Showing user timeline.");
List<Status> statuses = new ArrayList<Status>(0);
Paging paging = new Paging(page, count);
try {
statuses = twitter.getUserTimeline(keyWord, paging);
} catch (TwitterException e) {
log.error("Unable to find user timeline", e);
}
return statuses;
}
This code returns 100 tweets for the first fetch. In the second fetch, it retrieves 102 [100(last fetched tweets)+2 (new tweets)] if there new tweets posted by the user. Otherwise it returns the same 100 tweets for each and every fetch.
How do I solve getting tweets from the last fetch of tweets?
Upvotes: 0
Views: 740
Reputation: 2409
You can specify 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);
You can find lots of things here : , and also you can use sthg like that;
Query query = new Query("from:somebody").since("2011-01-02");
Twitter twitter = new TwitterFactory().getInstance();
QueryResult result = twitter.search(query);
Upvotes: 2