limit - How to get more than 20 results from a user timeline using processing and Twitter4j? -
i'm trying make sketch gets last 100 tweets specific user's twitter timeline. i'm using twitter4j , sketch works fine i've learned twitter4j default limits timeline results 20.
i've seen page learn getting more 100 when using queries, seems working differently when trying specific user's timeline. how retrieve more 100 results using twitter4j
thanks looking!
here sketch:
import twitter4j.conf.*; import twitter4j.internal.async.*; import twitter4j.internal.org.json.*; import twitter4j.internal.logging.*; import twitter4j.json.*; import twitter4j.internal.util.*; import twitter4j.management.*; import twitter4j.auth.*; import twitter4j.api.*; import twitter4j.util.*; import twitter4j.internal.http.*; import twitter4j.*; import twitter4j.internal.json.*; configurationbuilder cb = new configurationbuilder(); cb.setoauthconsumerkey("xxxxxx"); cb.setoauthconsumersecret("xxxxxx"); cb.setoauthaccesstoken("xxxxxx"); cb.setoauthaccesstokensecret("xxxxxx"); java.util.list statuses = null; twitter twitter = new twitterfactory(cb.build()).getinstance(); string username ="xxxxxx"; int numtweets = 100; string[] twarray = new string[numtweets]; try { statuses = twitter.getusertimeline(username); } catch(twitterexception e) { } (int i=0; i<statuses.size(); i++) { status status = (status)statuses.get(i); //println(status.getuser().getname() + ": " + status.gettext()); twarray[i] = status.getuser().getname() + ": " + status.gettext(); } println(twarray);
how this?
paging pg = new paging(); string username = "uzr"; void setup() { configurationbuilder cb = new configurationbuilder(); cb.setoauthconsumerkey("xxxx"); cb.setoauthconsumersecret("xxxx"); cb.setoauthaccesstoken("xxxx"); cb.setoauthaccesstokensecret("xxxx"); twitter twitter = new twitterfactory(cb.build()).getinstance(); int numberoftweets = 100; long lastid = long.max_value; arraylist<status> tweets = new arraylist<status>(); while (tweets.size () < numberoftweets) { try { tweets.addall(twitter.getusertimeline(username,pg)); println("gathered " + tweets.size() + " tweets"); (status t: tweets) if(t.getid() < lastid) lastid = t.getid(); } catch (twitterexception te) { println("couldn't connect: " + te); }; pg.setmaxid(lastid-1); } }
Comments
Post a Comment