简体   繁体   English

Twitter4j Stream无法在Eclipse上运行

[英]Twitter4j Stream Not working on Eclipse

The twitter4j stream was working a few weeks back but when I run it again it gives me this error. 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>

Here is my code: 这是我的代码:

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);
    }

I have a twitter4j.properties in the same folder as the source file. 我在与源文件相同的文件夹中有一个twitter4j.properties。 The weird thing is, it is able to run on a friend's eclipse workspace but somehow is unable to run on mine.The normal get tweets in a bulk with twitter4j core is working just fine but not stream. 奇怪的是,它能够在朋友的日食工作区上运行,但又无法在我的日食工作区上运行。使用twitter4j核心进行批量获取的普通tweet正常工作,但不能流式传输。 Any thoughts on this? 有什么想法吗?

The problem lies with the Date&Time of my system. 问题出在我系统的日期和时间上。 Apparently my Global Clock drifted. 显然我的全球时钟漂移了。 Therefore after setting the time back to normal and its working fine. 因此,将时间设置为正常后,即可正常工作。 Hope this helps those who faced the same problems. 希望这对遇到同样问题的人有所帮助。 Cheers 干杯

Do the following : 请执行下列操作 :

  1. Re-generate ur api keys 重新生成您的api密钥
  2. Change ur workspace 更改您的工作区

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM