That said (@mbaxi answer) I think that for a not really popular word the Stream API would be suitable for that task. I'm running this code for 5 minutes using the very popular "love" and got no warnings so far, also got about 25000 tweets in love...
I made this very simple and not precise timer just for the example sake... Although you said you don't want the text, it's is being printed to console...
Here an example
import twitter4j.util.*;
import twitter4j.*;
import twitter4j.management.*;
import twitter4j.api.*;
import twitter4j.conf.*;
import twitter4j.json.*;
import twitter4j.auth.*;
int startTime;
int tweetNumber;
PFont f ;
String theWord = "love";
TwitterStream twitterStream;
void setup() {
size(800, 100);
background(0);
f = createFont("SourceCodePro-Regular", 25);
textFont(f);
openTwitterStream();
startTime = minute();
}
void draw() {
background(0);
int passedTime = minute() - startTime;
text("Received " + nf(tweetNumber, 5) + " tweets with the word: " + theWord, 30, height - 50);
text("in last " + nf(passedTime, 3) + " minutes", 30, height - 25);
}
// Stream it
void openTwitterStream() {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("-----FILL-----");
cb.setOAuthConsumerSecret("-----FILL-----");
cb.setOAuthAccessToken("-----FILL-----");
cb.setOAuthAccessTokenSecret("-----FILL-----");
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
FilterQuery filtered = new FilterQuery();
// if you enter keywords here it will filter, otherwise it will sample
String keywords[] = {
theWord
};
filtered.track(keywords);
twitterStream.addListener(listener);
if (keywords.length==0) {
// sample() method internally creates a thread which manipulates TwitterStream
twitterStream.sample(); // and calls these adequate listener methods continuously.
} else {
twitterStream.filter(filtered);
}
println("connected");
}
// Implementing StatusListener interface
StatusListener listener = new StatusListener() {
//@Override
public void onStatus(Status status) {
tweetNumber++;
System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
}
//@Override
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
}
//@Override
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
}
//@Override
public void onScrubGeo(long userId, long upToStatusId) {
System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
}
//@Override
public void onStallWarning(StallWarning warning) {
System.out.println("Got stall warning:" + warning);
}
//@Override
public void onException(Exception ex) {
ex.printStackTrace();
}
};