简体   繁体   中英

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.

[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. 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. 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
  2. Change ur workspace

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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