Twitter API access suddenly stopped working



Hello -

this evening, I was working on an application that accesses the Twitter API. The developer account for this is @deedee3752 (interesting story behind the name, by now I would have chosen @deedee5502 or so).

With every access, I am checking the rate limit; it never went below 850 remaining requests in the current 15 mins interval.

Nevertheless, I ran into the following exception repeatedly:

2019-03-06 22:57:10.130 ERROR 29108 — [ scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task.

twitter4j.TwitterException: 401:Authentication credentials ( 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.”}

at twitter4j.HttpClientImpl.handleRequest( ~[twitter4j-core-4.0.7.jar:4.0.7]
at twitter4j.HttpClientBase.request( ~[twitter4j-core-4.0.7.jar:4.0.7]
at twitter4j.HttpClientBase.get( ~[twitter4j-core-4.0.7.jar:4.0.7]
at twitter4j.TwitterImpl.get( ~[twitter4j-core-4.0.7.jar:4.0.7]
at twitter4j.TwitterImpl.getUserTimeline( ~[twitter4j-core-4.0.7.jar:4.0.7]
at twitter4j.TwitterImpl.getUserTimeline( ~[twitter4j-core-4.0.7.jar:4.0.7]
at infogralis.twitter.UserTimelineService.scanOneTimeline( ~[main/:na]

I made sure that I have the correct consumerKey, consumerSecret, accessToken and accessTokenSecret. Everything is setup correctly, and it used to work, but now it does not, even after re-generating the accessToken and accessTokenSecret.

I do not think that I abused/hammered the Twitter API with less than 100 accesses over 20 minutes or so, and I should be well within the rate limit.

Could you please help me in determining why the API access suddenly stopped working? Did I do something wrong?

Thanks for your help and support!


If you try to request a user timeline from a Protected account, you can also get this “Not authorized.” error.

If it’s not a protected user, this might be the clock sync issue if everything else is in order - if your system clock is off by a few minutes you can get this error.

Another thing that could be wrong is SSL certs with java - updating something like ca-certificates-java or your OS equivalent might be worth looking into.

Another common cause is if Maven / other build tools fail to include the .properties file with the keys for Twitter4J (if you’re configuring it that way)


Thanks for your answer, Igor!

Turns out one of the user switches between protecting and unprotecting his account. That was a bit hard to detect. Problem solved now.