【问题标题】:Twitter4j Stream Not working on EclipseTwitter4j Stream 在 Eclipse 上不起作用
【发布时间】:2017-03-11 20:05:04
【问题描述】:

twitter4j 流几周前还在工作,但是当我再次运行它时,它给了我这个错误。

[Twitter Stream consumer-1[initializing]] INFO twitter4j.TwitterStreamImpl - Establishing connection.
[Twitter Stream consumer-1[Establishing connection]] INFO twitter4j.TwitterStreamImpl - 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\n<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/1.1/statuses/filter.json'. Reason:
<pre>    Unauthorized</pre>
</body>
</html>

这是我的代码:

TwitterStream tws = new TwitterStreamFactory().getInstance();
        StatusListener listener = new StatusListener(){

            @Override
            public void onException(Exception e) {
                e.printStackTrace();

            }

            @Override
            public void onDeletionNotice(StatusDeletionNotice arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onScrubGeo(long arg0, long arg1) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStallWarning(StallWarning arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStatus(Status status) {
                // TODO Auto-generated method stub
                System.out.println(status.getText());
            }

            @Override
            public void onTrackLimitationNotice(int arg0) {
                // TODO Auto-generated method stub

            }

        };

        tws.addListener(listener);
        FilterQuery filter = new FilterQuery();
        filter.track("Star wars");
        filter.language("en");
        tws.filter(filter);
    }

我在与源文件相同的文件夹中有一个 twitter4j.properties。 奇怪的是,它能够在朋友的 eclipse 工作区上运行,但不知何故无法在我的工作区上运行。带有 twitter4j 核心的批量获取推文的正常工作正常但不能流式传输。对此有什么想法吗?

【问题讨论】:

  • HTTP 错误 401 表示未经授权的访问。您最近是否更改了密码或 twitter 唯一密钥?
  • 抱歉没有更新...问题出在我系统的日期和时间上。显然我的全球时钟漂移了。因此,将时间设置回正常后,它工作正常。
  • 你可以说同样的答案。它可以帮助面临这个问题的人。很高兴你自己搞定了!

标签: java twitter4j


【解决方案1】:

问题在于我系统的日期和时间。显然我的全球时钟漂移了。因此,在将时间设置回正常并且工作正常后。希望这可以帮助那些面临同样问题的人。干杯

【讨论】:

    【解决方案2】:

    执行以下操作:

    1. 重新生成你的 api 密钥
    2. 改变你的工作空间

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-03
      • 2015-09-29
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 2018-03-01
      • 1970-01-01
      相关资源
      最近更新 更多