How to use rate limiting with twitter4j to avoid getting banned
I haven't banned Twitter yet. However, I would like to avoid this. I have a simple using StatusListener method to pull tweets according to an array of keywords, after which they will be filtered by the array of branches. As I understand it, StatusLintener only receives new tweets and continues to work until the application is stopped.
I think this code will reach the speed limit after a while. So, is there a way to handle this? Authentication request can ask 350 times per hour, how does it work with StatusLintener?
public static void getTweetsKeywords(ConfigurationBuilder cb, String[] keywords, String[] branches,){
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
StatusListener listener = new StatusListener() {
public void onStatus(Status status) {
System.out.println(status.getCreatedAt()+" - "+"@" + status.getUser().getScreenName() + " - " + status.getText());
}
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
}
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
}
public void onScrubGeo(long userId, long upToStatusId) {
System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
}
public void onException(Exception ex) {
ex.printStackTrace();
}
};
FilterQuery fq = new FilterQuery();
fq.track(keywords);
twitterStream.addListener(listener);
twitterStream.filter(fq);
}
thank
+1
source to share