【发布时间】:2016-04-22 03:34:37
【问题描述】:
我使用了 Twitter4j 中“代码示例”部分中的代码:
public static void main(String[] args) throws TwitterException, IOException{
StatusListener listener = new StatusListener(){
public void onStatus(Status status) {
System.out.println(status.getUser().getName() + " : " + status.getText());
}
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {}
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {}
public void onException(Exception ex) {
ex.printStackTrace();
}
};
TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
twitterStream.addListener(listener);
// sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
twitterStream.sample();
}
如您所见,上面的代码中有一个 println,位于方法“onStatus”中。下图显示了我主要从该代码中获得的信息。正常吗?
question marks...question marks everywhere
确实,我只过滤用户名中没有问号的状态,我几乎什么也没得到。此外,我还应该过滤位置公开的用户。关于这一点,我还问有什么区别:
user.isGeoEnabled()
和
user.getLocation() != ""
【问题讨论】:
标签: java twitter twitter4j twitter-streaming-api