I am using twitter gem to interact with twitter APIs. I am using single user authentication
(not application only authentication) as shown here https://github.com/sferik/twitter/blob/master/examples/Configuration.md#single-user-authentication
I have a page, where user clicks to sign in with twitter (I am using http://sign-in-with-twitter.herokuapp.com/)
Once user gets authenticated, I get token
and secret
and then use my app consumer_key
and consumer_secret
alongwith signed in user's token
and secret
to initialize Twitter::REST::Client
as shown below
module Ktwitter
class Manager
attr_accessor :client
def initialize token, token_secret
@client = Twitter::REST::Client.new do |config|
config.consumer_key = XXXXXXXXXXXXX
config.consumer_secret = ZZZZZZZZZZZZZ
config.access_token = token
config.access_token_secret = token_secret
end
end
def user
@client.user
end
end
end
obj = Ktwitter::Manager.new request.env['omniauth.auth']['credentials']['token'], request.env['omniauth.auth']['credentials']['secret']
I have a (pry) breakpoint and there I run obj.client.user
15 times (in less than 1 minute - just keep hitting) and after that I get rate_limit warning
[1] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[2] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[3] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[4] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[5] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[6] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[7] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[8] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[9] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[10] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[11] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[12] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[13] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[14] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[15] pry(#<T>)> obj.client.user
=> #<Twitter::User id=177777>
[16] pry(#<T>)> obj.client.user
Twitter::Error::TooManyRequests: Rate limit exceeded
from /Users/xyz/.rvm/gems/ruby-2.1.1/gems/twitter-5.8.0/lib/twitter/rest/response/raise_error.rb:17:in `on_complete'
I assume twitter gem client.user
makes call to /1.1/users/show.json
https://github.com/sferik/twitter/blob/master/lib/twitter/rest/users.rb#L257 ?
This means twitter api gets restriction rate limit on 15 calls in 15 minutes window? But per API documentation https://dev.twitter.com/docs/api/1.1/get/users/show it is 180, not 15. So why am I being restricted after 15 calls itself?
When I uses Twitter API console https://dev.twitter.com/console and there I make call to /1.1/get/users/show
and it shows 180 as rate limit. So I am not sure why does twitter gem
end up getting limit after 15 calls only.
Also is there anyway, that I can get the whole response header in twitter
gem, so that debugging will be easy to read x-rate-limit-limit
and x-rate-limit-remaining
Any help will be appreciated.