[英]Why is twitter4j TwitterStream not filtering user's tweets?
[英]Is it normal that sampling tweets using TwitterStream as in Twitter4J code example, I get just mainly question marks as user name and status?
我使用了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();
}
如您所见,在上面的代码中,在“ onStatus”方法内部有一个println。 下图显示了我主要从该代码中获得的信息。 正常吗
的确,我只过滤用户名中没有问号的状态,我几乎什么也没有。 此外,我还应该过滤公开位置的用户。 关于这一点,我也想问一下两者之间有什么区别?
user.isGeoEnabled()
和
user.getLocation() != ""
您将获得的响应是UTF-8编码的https://dev.twitter.com/tags/utf-8
如果您查看输出中的某些帐户,它们将包含非西欧字符https://twitter.com/tomokichi_koyo 。 这些正在破坏输出。
尝试改为写入文件,然后使用支持UTF-8的编辑器打开。 关于将Java和操作系统设置为默认为UTF-8的方法有多种答案,但是您需要查找特定的组合https://stackoverflow.com/search?q=windows+console+java+utf-8
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.