想要查看在线tweet流,我首先授权了凭据,然后实现了StatusListener方法,然后又实现了onStatus方法,该方法为我提供了状态变量以显示状态,我还引入了TwitterStream,但我看不到这些tweet,我曾经能够昨天在添加断点时看到推文,但现在它不再跳转到断点了,我的代码如下
package com.example.mapo;
import twitter4j.FilterQuery;
import twitter4j.StallWarning;
import twitter4j.Status;
import twitter4j.StatusDeletionNotice;
import twitter4j.StatusListener;
import twitter4j.TwitterStream;
import twitter4j.TwitterStreamFactory;
import twitter4j.User;
import twitter4j.conf.ConfigurationBuilder;
public class SimpleStream {
public static void main(String[] args) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey("**************");
cb.setOAuthConsumerSecret("*****************************");
cb.setOAuthAccessToken("***************************");
cb.setOAuthAccessTokenSecret("*******************");
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
StatusListener listener = new StatusListener() {
@Override
public void onException(Exception e) {
}
@Override
public void onStatus(Status status) {
User user = status.getUser();
// gets Username
String username = status.getUser().getScreenName();
System.out.println(username);
String profileLocation = user.getLocation();
System.out.println(profileLocation);
long tweetId = status.getId();
System.out.println(tweetId);
String content = status.getText();
System.out.println(content +"\n");
}
@Override
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
}
@Override
public void onTrackLimitationNotice(int i) {
}
@Override
public void onScrubGeo(long l, long l1) {
}
@Override
public void onStallWarning(StallWarning stallWarning) {
}
};
FilterQuery fq = new FilterQuery();
String keywords[] = {"ireland"};
fq.track(keywords);
twitterStream.addListener(listener);
twitterStream.filter(fq);
System.out.println(twitterStream.sample());
twitterStream.cleanUp();
twitterStream.shutdown();
}
}