我对twitter4j库有一个非常奇怪的问题 当我运行我的程序时,我的eclipse控制台上有下面的行,这就是全部 没有例外,没有结果,它只是永远被卡住了:
[Tue Jul 28 10:39:49 KST 2015]Establishing connection.
[Tue Jul 28 10:39:52 KST 2015]Connection established.
[Tue Jul 28 10:39:52 KST 2015]Receiving status stream.
(我的帐户上只运行了一个Twitter应用程序实例)。 相同的代码在我的Mac上运行得很好,但我的Mac和Windows在同一个网络上。
这是我的代码:
public class TFireHouse {
public static void main(String[] args) {
ConfigurationBuilder confBuilder = new ConfigurationBuilder();
confBuilder = new ConfigurationBuilder();
confBuilder.setDebugEnabled(true);
confBuilder.setOAuthConsumerKey("************************");
confBuilder.setOAuthConsumerSecret(***********************");
confBuilder.setOAuthAccessToken("***********************");
confBuilder.setOAuthAccessTokenSecret("**********************");
TwitterStream tweetStream = new TwitterStreamFactory(confBuilder.build()).getInstance();
StatusListener statusListener = new StatusListener() {
String userName;
String tweet;
long tweetId;
HashtagEntity hashtags;
String timestamp;
String profileLocation;
int retweetCount;
StringBuffer sb = null;
FileManager fileWriter = null;
@Override
public void onException(Exception arg0) {}
@Override
public void onTrackLimitationNotice(int arg0) {}
@Override
public void onStallWarning(StallWarning arg0) {}
@Override
public void onScrubGeo(long arg0, long arg1) {}
@Override
public void onDeletionNotice(StatusDeletionNotice arg0) {}
@Override
public void onStatus(Status status) {
fileWriter = new FileManager();
sb = new StringBuffer();
User user = status.getUser();
userName = status.getUser().getScreenName();
tweet = status.getText();
tweetId = status.getId();
timestamp = status.getCreatedAt().toString();
profileLocation = user.getLocation();
retweetCount = status.getRetweetedStatus().getRetweetCount();
sb.append("{");
sb.append("\"tweetId\":" + "\"" + tweetId + "\",");
sb.append("\"userName\":" + "\"" + userName + "\",");
sb.append("\"tweet\":" + "\"" + tweet + "\",");
sb.append("\"retweetCount\":" + "\"" + retweetCount + "\",");
sb.append("\"postedTime\":" + "\"" + timestamp + "\",");
sb.append("\"hashtags\":" + "\"" + hashtags.toString() + "\",");
sb.append("\"profileLocation\":" + "\"" + profileLocation + "\"");
sb.append("}");
fileWriter.fileWriter(sb);
System.out.println(sb);
}
};
FilterQuery bbcFilter = new FilterQuery();
String bbc[] = {"BBC"};
String lan[] = {"en"};
bbcFilter.track(bbc).language(lan);
tweetStream.addListener(statusListener);
tweetStream.filter(bbcFilter);
}
}