Skip to content

Instantly share code, notes, and snippets.

@raysrashmi
Created June 14, 2012 17:10
Show Gist options
  • Save raysrashmi/2931542 to your computer and use it in GitHub Desktop.
Save raysrashmi/2931542 to your computer and use it in GitHub Desktop.
authentication error while using Twitter.user_search('rays')
```ruby
1.9.3p194 :006 > Twitter.configure do |config|
1.9.3p194 :007 > config.consumer_key = PROVIDER['twitter']['key']
1.9.3p194 :008?> config.consumer_secret = PROVIDER['twitter']['secret']
1.9.3p194 :009?> config.oauth_token = PROVIDER['twitter']['oauth_token']
1.9.3p194 :010?> config.oauth_token_secret = PROVIDER['twitter']['oauth_token_secret']
1.9.3p194 :011?> end
=> Twitter
1.9.3p194 :012 > Twitter.user_search('rays')
Twitter::Error::Unauthorized: Could not authenticate with OAuth.
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/twitter-2.5.0/lib/twitter/response/raise_client_error.rb:18:in `on_complete'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/faraday-0.8.1/lib/faraday/response.rb:9:in `block in call'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/faraday-0.8.1/lib/faraday/response.rb:63:in `on_complete'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/faraday-0.8.1/lib/faraday/response.rb:8:in `call'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/faraday-0.8.1/lib/faraday/request/url_encoded.rb:14:in `call'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/faraday-0.8.1/lib/faraday/request/multipart.rb:13:in `call'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/twitter-2.5.0/lib/twitter/request/oauth.rb:17:in `call'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/twitter-2.5.0/lib/twitter/request/multipart_with_file.rb:17:in `call'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/faraday-0.8.1/lib/faraday/connection.rb:226:in `run_request'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/twitter-2.5.0/lib/twitter/request.rb:23:in `request'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/twitter-2.5.0/lib/twitter/request.rb:11:in `get'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/twitter-2.5.0/lib/twitter/client.rb:2413:in `user_search'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/twitter-2.5.0/lib/twitter.rb:17:in `method_missing'
from (irb):12
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /Users/rashmiyadav/mprojects/doghouse/vendor/ruby/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'1.9.3p194 :013 >
```
```ruby
PROVIDER = YAML.load_file("#{Rails.root}/config/provider.yml")[Rails.env]
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, PROVIDER['twitter']['key'], PROVIDER['twitter']['secret'] #,PROVIDER['twitter']['oauth_token'] ,PROVIDER['twitter']['oauth_token_secret']
end
#
Twitter.configure do |config|
config.consumer_key = PROVIDER['twitter']['key']
config.consumer_secret = PROVIDER['twitter']['secret']
config.oauth_token = PROVIDER['twitter']['oauth_token']
config.oauth_token_secret = PROVIDER['twitter']['oauth_token_secret']
end
```
development:
twitter:
key: "erEWlf5j2Vxiv5mrV2KAg"
secret: "CFOGkf2AYx1XdNu5ceaxfIn0Rc9QgZitvaXBbUk"
oauth_token: "13663922-ksGwrZSjrfHUJZWqUyEvIgfcX1qG0kDLcADPewj38"
oauth_token_secret: "j6oUWZoy3wocQS2Rs6cw8B33knDfRa3QBDJmjTl7I0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment