Ruby Twitter Gem Limit Exceeded

I am trying to use ruby ​​gem twitter ( https://github.com/sferik/twitter ) to get user followers from twitter api.

According to the documentation ( https://dev.twitter.com/docs/api/1/get/followers/ids ), twitter returns 5,000 users in a single request. According to the speed limit settings, twitter allows me to make 15 calls in 15 minutes ( https://dev.twitter.com/docs/rate-limiting/1.1/limits )

Problem:

When I get followers of a user with more than 75,000 followers (5000 * 15), I get a "Speed ​​limit exceeded" error.

When I use the gem method Twitter.followers_id (user), I get all the followers automatically, and not in 5000 buckets with a cursor. I think this stone takes care of this internally, and therefore I cannot control or delay these requests.

The gemstone documentation has an example of a speed limit ( https://github.com/sferik/twitter#rate-limiting ), but I don’t know if it will take care of already received users or will start from fresh ones again.

My question is: How and when do I apply a throttling mechanism for this to get all the followers?

Hi

+7
source share
2 answers

The workaround for this problem is very well explained here .

MAX_ATTEMPTS = 3 num_attempts = 0 begin num_attempts += 1 retweets = Twitter.retweeted_by_user("sferik") rescue Twitter::Error::TooManyRequests => error if num_attempts <= MAX_ATTEMPTS # NOTE: Your process could go to sleep for up to 15 minutes but if you # retry any sooner, it will almost certainly fail with the same exception. sleep error.rate_limit.reset_in retry else raise end end 
+6
source

Add the sleep command to the cursor_from_response_with_user method in the Twitter stone, which is located in lib / twitter / api / utils.rb

https://github.com/sferik/twitter/blob/master/lib/twitter/api/utils.rb

 def cursor_from_response_with_user(collection_name, klass, request_method, path, args, method_name) puts "sleeping 60" sleep 60 arguments = Twitter::API::Arguments.new(args) merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name] cursor_from_response(collection_name, klass, request_method, path, arguments.options, method_name) end 

Each response to the cursor will take at least 60 seconds, so you won’t miss 15 requests in 15 minutes. This is a bit hacky, but it will work until this question is sorted for 75K + follower_ids.

0
source

All Articles