Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upGet access token only once and not before every request #441
Comments
This comment has been minimized.
This comment has been minimized.
|
That's a good catch and a very useful error report. I have verified the problem with the test case that you have supplied. The problem stems from the difference in behaviour of the As a temporary workaround, you start creating require "rubygems"
require "twitter" # 4.8.1
twitter = Twitter::Client.new(consumer_key: YOUR_COMSUMER_KEY, consumer_secret: YOUR_COMSUMER_SECRET)
60.times do |count|
puts "request #{count+1}"
# first get 10 tweets
tweets = twitter.user_timeline("torial", count: 10, exclude_replies: true)
# second get oembed for first tweet
twitter.oembed(tweets.first.id, align: 'center')
sleep 0.5
endI have narrowed the problem down to this line in return @client if instance_variable_defined?(:@client) && @client.hash == options.hashSince the @sferik, I am not exactly sure how this should be mitigated? Could you point me in the right direction? |
This comment has been minimized.
This comment has been minimized.
|
I’m in the process of re-thinking this interface for 5.0. For now, you can use the temporary workaround mentioned above. |
This comment has been minimized.
This comment has been minimized.
thomasbaustert
commented
Aug 15, 2013
|
Thanks for the quick response. I changed the code like recommended and it works now. |
This comment has been minimized.
This comment has been minimized.
|
One thought would be to explicitly invalidate the default client when the configuration is modified, instead of relying on the |
This comment has been minimized.
This comment has been minimized.
|
I’ve decided to remove global configuration from version 5 of the gem. This allows code simplification, removes possible confusion, and ensures that configuration is threadsafe. |
thomasbaustert commentedAug 15, 2013
The code below raises a
Twitter::Error::Forbidden: Unable to verify your credentialsafter around 50 calls. (If only user_timeline or oembed is called it works.)
Note that this is not a problem of rate limits cause user_timeline allows 300 requests
for 15 minutes time window, oembed allows 180.
I guess the error is because the Twitter gem does a /oauth2/token request before every
user_timeline and oembed request, not just one at all. And twitter shuts up:
The same happens without the twitter gem (using Curb for example). Pseudo code:
Doing the calls with one call to /oauth2/token at the beginning works. Pseudo code:
See https://dev.twitter.com/discussions/20548 on not negotiate the token within a loop.