I'm working on writing a simple program to fetch tweets for an information retrieval class (later I will be learning to index and search through them). For now, I just want to gather data. I'm using the twitter4j API and am having trouble understanding the Paging class and how it works. Below is a snippet of code:
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
Paging paging = new Paging(2,40);
try{
List<Status> statuses = twitter.getUserTimeline("google", paging);
System.out.println(paging);
for(Status status : statuses)
{
System.out.println(status.getText());
}
System.out.println("\n\n\n");
paging.setPage(2);
statuses = twitter.getUserTimeline("google",paging);
for(Status status : statuses)
{
System.out.println(status.getText());
}
}
catch(TwitterException e){
e.printStackTrace();
}
My hope was that the second call to twitter.getUserTimeline
would return the next 40 tweets from Google as this example seems to suggest, but upon inspection, both return the same 40 tweets. Can someone then explain what the Paging class actually does?
Your first call should request the first page Paging paging = new Paging(1, 40);
, not the second one.