我有一個應用程序,每天運行,並已工作了幾個月。它使用twitter4j v3.0.3。401驗證錯誤檢索推文
幾個星期前,它開始拋出常見的401例外:
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\/statuses\/user_timeline.json","error":"Not authorized."}
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=4be80492 or
http://www.google.co.jp/search?q=0a6306df
TwitterException{exceptionCode=[4be80492-0a6306df], statusCode=401, message=null, code=-1, retryAfter=-1, rateLimitStatus=RateLimitStatusJSONImpl{remaining=112, limit=180, resetTimeInSeconds=1448156737, secondsUntilReset=428}, version=4.0.4}
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:164)
at twitter4j.HttpClientBase.request(HttpClientBase.java:57)
我已經(在寫作時最新)更新至V4.0.4 &確認所有接入和客戶端令牌的正確性。我也嘗試創建一個全新的應用程序,並使用這些令牌。我已同步我的系統時鐘。一切都無濟於事。
我來源:
val config = new ConfigurationBuilder()
.setOAuthConsumerKey(conf.getString("twitter.api.key"))
.setOAuthConsumerSecret(conf.getString("twitter.api.secret"))
.setOAuthAccessToken(conf.getString("twitter.access.token"))
.setOAuthAccessTokenSecret(conf.getString("twitter.access.secret"))
.build()
val twitter = new TwitterFactory(config).getInstance
def statuses(handle: String, since: Long): Stream[Status] = {
@tailrec
def loop(page: Int, acc: Stream[Status]): Stream[Status] = {
val paging = new Paging(page, since)
val xs = twitter.getUserTimeline(handle, paging).iterator().asScala.toSeq
val stream = Stream.concat(acc, xs.filterNot(_.getText.startsWith("@")).filterNot(_.getText.startsWith("RT ")).toStream)
if (xs.size < 20) stream
else loop(page + 1, stream)
}
loop(1, Stream.empty)
}
它未能在twitter.getUserTimeline
。
爲什麼在代碼,配置或我的Twitter帳戶中沒有任何更改時會失敗?
我排除了鍵&時鐘同步。我還能看到什麼?
整個項目可在https://github.com/Synesso/tweet-mail測試(它需要一些設置,按照自述 - 但可能不需要SMTP設置)。
您可能需要catcert.pem'的'喜歡https://github.com/jublonet/codebird-php/blob/develop/src/cacert.pem一個新版本 - 包含從Twitter最新的證書數據。 –
我添加了信任證書https://dev.twitter.com/overview/api/ssl _賽門鐵克3類的安全服務器CA - G4根證書與串行:51:3F:B9:74:38:70:B7:34 :40:41:8d:30:93:06:99:ff_到我的系統,但仍然失敗。有沒有一種方法可以通過twitter4j api將應用程序信任它? – Synesso
我需要將它添加到JRE cacerts。謝謝Terence。 – Synesso