Cron job raise Forbidden (Unable to verify your credentials) after 51 request to "/1.1/statuses/user_timeline.json"


We are using the ruby twitter gem ( to connect to twitter, but I don’t think it is important here.

We have a cron job that fetches the latest entries of user timelines twice a day.
We are using Application-only authentication.

The first 50 or 51 out of 58 requests work fine and return the tweets
but all other fail with “Twitter::Error::Forbidden: Unable to verify your credentials”.
(Same happens if we use the reverse order of users)

According to the rate limit is 300 requests per window
and shouldn’t be our problem.

Does anyone know what the issue might be?



Have you tracked it down to a more specific error being sent to you from the API? Are you sure that there aren’t more API calls behind leveraged than you’re expecting, perhaps to other endpoints like account/verify_credentials? Get closer to the API to better understand what’s going on. Be sure and check for conditions like rate limiting and any other exceptions that might occur, even if you don’t think you’re going to hit them.


Thanks for your answer.
I will track it down to better understand what’s going on.
Requesting the bearer token is not decreasing the limit rate, right?


It shouldn’t – but you also shouldn’t be trying to negotiate it within a loop at all. Bearer tokens are meant to be long lived and there are limits to how many times in a small window of time you can try to re-negotiate it.


I tracked it down. The twitter gem does a /oauth2/token before every requests.
Pseudo code:

60.times do |count| get_access_token user_timeline get_access_token oembed end

See for a workaround.


Great, glad you found the bug!