【发布时间】: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 唯一密钥?
-
抱歉没有更新...问题出在我系统的日期和时间上。显然我的全球时钟漂移了。因此,将时间设置回正常后,它工作正常。
-
你可以说同样的答案。它可以帮助面临这个问题的人。很高兴你自己搞定了!