0

I'm using twitter4j version 2.2.5. setPage() doesn't seem to work if I use it with setSince() and setUntil(). See the following code:

Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
AccessToken accessToken = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
twitter.setOAuthAccessToken(accessToken);
int page = 1;
while(true) {
    Query query = new Query("from:someUser");
    query.setSince("2012-01-01");
    query.setUntil("2012-07-05");
    query.setRpp(100);
    query.setPage(page++);
    QueryResult qr = twitter.search(query);
    List<twitter4j.Tweet> qrTweets = qr.getTweets();
    if(qr.getTweets().size() == 0) break;
    for(twitter4j.Tweet t : qrTweets) {
        System.out.println(t.getId() + " " + t.getText());
    }
}

The code inside the loop is only executed once if I use setSince() and setUntil() methods. But without them, setPage() seems to work and I get more tweet results.

Any ideas why this is happening?

vikiiii
  • 9,246
  • 9
  • 49
  • 68
  • Are you sure that no tweets returned is greater than 100 – Abhishek bhutra Jul 09 '12 at 13:48
  • I just learned that you cannot get tweets created over 1 week before if you use Query. Interestingly enough, setRpp() doesn't seem to be working right. If the user has a total of 80 tweets in the past week, and I set rpp=40, the query still returns all 80 tweets. Have you encountered this as well Abhishek? – Paul Rivera Jul 10 '12 at 09:11

1 Answers1

0

Your code appears to be working for me. It only returns tweets from the past nine days, but that's expected (approximately) according to your comment.

You mentioned in the question that the loop only ran once with rpp=100, and you said in a comment that all 80 of the user's tweets were returned when rpp=40. I think that would indicate that the code is working as expected. If the user only has 80 tweets, the loop only should run once when rpp=100, and it should execute twice and display all their tweets when rpp=40. Try displaying the page number as soon as you enter the while loop so you can see how many times the loop runs.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880