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


#1

We are using the ruby twitter gem (https://github.com/sferik/twitter) 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 https://dev.twitter.com/docs/rate-limiting/1.1/limits the rate limit is 300 requests per window
and shouldn’t be our problem.

Does anyone know what the issue might be?

Thanks


#2

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.


#3

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?


#4

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.


#5

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 https://github.com/sferik/twitter/issues/441 for a workaround.


#6

Great, glad you found the bug!