简体   繁体   中英

Twitter4j how can i get any twitter handle tweets from it's 1'st tweets

i am using this code i get an error TwitterException 429 trying to fecth the tweets. i want to fecth whole tweets of twitter account from starting. how to solve twitter rate limit issue.

    int limitRateCounter=0;
int countOfTweets=0; int numberOfTweets = 3500; long lastID = Long.MAX_VALUE; ArrayList<Status> status = new ArrayList<Status>();while (status.size () < numberOfTweets) { try {.out.print("\nlimit counter = "+limitRateCounter);.out.print("\t tweetsCounter = "+countOfTweets);
List<Status>  listOfStatus=
twitter.getUserTimeline(tweeterHandle,pg);
/* making twitter request */
countOfTweets=countOfTweets+listOfStatus.size();
status.addAll(listOfStatus);
limitRateCounter++; 
// println("Gathered " + tweets.size() + " tweets");
for (Status t: status) 
if(t.getId() < lastID) lastID = t.getId();
}
catch (TwitterException te) {
System.out.println("Couldn't connect: " + te);
//twitter=getTwitterDetails2();
break;
}; 
pg.setMaxId(lastID-1); /* add pagging max id */
} 

after 120 request .getUserTimeline(tweeterHandle,pg); methode not fetching new tweets after some time get exception.

Twitter4j uses Twitter API to access Twitter data. This API has limits in the number of invocations as is specified here:

You seem to be facing this problem right now. Basically your code needs to wait before making another call until you are again inside the API rate limits. Take into account that the rate limit is per "access token" as the documentation specifies, so you could increase the number of calls your code can make if you provide it with more access tokens, but in the end you will have a (bigger) limit.

在twitter(10)上创建几个帐户,然后将访问令牌放入数组

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM