I pasted below my running code in java. You can use it for the same purpose:
//First we need to have a twitter object with a valid auth token.
public static ConfigurationBuilder confBuilder = null;
public static Configuration config = null;
public static Twitter twitterObj = null;
confBuilder = new twitter4j.conf.ConfigurationBuilder();
confBuilder.setDebugEnabled(true);
confBuilder.setOAuthConsumerKey("consumerKey");
confBuilder.setOAuthConsumerSecret("consumerSecret");
confBuilder.setOAuthAccessToken("accessToken");
confBuilder.setOAuthAccessTokenSecret("accessTokenSecret");
config = confBuilder.build();
twitter4j.TwitterFactory tf = new twitter4j.TwitterFactory(config);
twitterObj = tf.getInstance(); //Here, finally we got the twitter object.
//Later, we need to use streaming function which is also like this:
TwitterStream twitterStream = new TwitterStreamFactory(config).getInstance();
StatusListener statusListener = new StatusListener() {
private int count = 0;
private long originalTweetId = 0;
@Override
public void onStatus(Status status) {
// status object here is the tweet object that caught by the stream. You can do whatever you want with it.
}
@Override
public void onDeletionNotice(StatusDeletionNotice sdn) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void onTrackLimitationNotice(int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void onScrubGeo(long l, long l1) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void onStallWarning(StallWarning sw) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void onException(Exception ex) {
logWriter.WriteErrorLog(ex, "onException()");
}
};
FilterQuery fq = new FilterQuery();
String keywords[] = {keyword};
fq.track(keywords);
twitterStream.addListener(statusListener);
twitterStream.filter(fq);
// I hope this is what you are looking for. Good luck!