在 Twitter4J 代码示例中使用 TwitterStream 对推文进行采样是否正常,我得到的主要是问号作为用户名和状态?

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 中 "code example" 部分中的代码:

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

的确,我只过滤用户名中没有问号的状态,我几乎什么都没有。此外,我还应该过滤位置为 public 的用户。关于这一点,我也想问一下有什么区别:

user.isGeoEnabled()

user.getLocation() != ""

您将得到的回复是 UTF-8 编码的https://dev.twitter.com/tags/utf-8

如果您查看输出中的某些帐户,它们包含 non-western 个欧洲字符 https://twitter.com/tomokichi_koyo。这些正在破坏输出。

尝试改为写入文件并使用支持 UTF-8 的编辑器打开。关于设置 java 和您的 OS 默认为 UTF-8 有多种答案,但您需要寻找特定的组合 https://whosebug.com/search?q=windows+console+java+utf-8