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

时间:2016-01-16 17:13:04

标签: java twitter twitter4j twitter-streaming-api

我使用了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() != ""

1 个答案:

答案 0 :(得分:1)

您将获得的回复是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