我正在使用 Twitter4j 版本 3.0.3。
我正在尝试提取关注者 ID 并使用 OAuth。我已经使用 Twitter4j 多年,并且对该框架比较有经验。
然而,奇怪的事情发生了:我的程序将运行良好,然后间歇性地抛出以下堆栈跟踪:
Exception in thread "main" 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.
{"request":"\/1.1\/followers\/ids.json?user_id=20801287&cursor=-1&include_entities=1&include_rts=1","error":"Not authorized"}
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=92c30ec6 or
http://www.google.co.jp/search?q=19400604
TwitterException{exceptionCode=[92c30ec6-19400604], statusCode=401, message=null, code=-1, retryAfter=-1, rateLimitStatus=RateLimitStatusJSONImpl{remaining=6, limit=15, resetTimeInSeconds=1362898120, secondsUntilReset=890}, version=3.0.3}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:177)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:89)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1817)
at twitter4j.TwitterImpl.getFollowersIDs(TwitterImpl.java:400)
它将上面的内容抛出到以下行:
IDs ids= twitter.getFollowersIDs(id,cursor);
上面的行执行得很好,然后没有警告就失败了。
注意:我正在检查速率限制,上次遇到此问题时,以下行拉取的速率限制 JSON 对象是(如下):
RateLimitStatus rls=twitter.getRateLimitStatus().get("/followers/ids")
RateLimitStatusJSONImpl{remaining=7, limit=15, resetTimeInSeconds=1362898120, secondsUntilReset=890}
我以为这可能是 Twitter 的间歇性问题,但现在已经持续了几天了。
我已经在不同的机器上尝试过,但遇到了完全相同的问题。
大约 20 次调用中就会出现一次以这种方式失败的调用。
我也在SE上读过类似的问题:
Twitter4j 401 身份验证 https://stackoverflow.com/questions/7501757/twitter4j-401-authentication-- 然而,这是 OAuth 不起作用的情况 -- 在我的例子中,它似乎工作正常,直到它不起作用为止。
twitter4j:即使我已经设置了凭证错误? https://stackoverflow.com/questions/6681399/twitter4j-getting-credential-errors-even-though-i-had-set-them——同样,这里与我的情况相似的地方并不多。
twitter4j 的 Oauth 问题 https://stackoverflow.com/questions/7152735/problem-in-oauth-with-twitter4j-- 建议将应用程序注册为网络应用程序,我已经完成了,我已经填写了回调网址(尽管它什么也没做),但仍然没有运气。