Anoel
Anoel

Reputation: 1063

Omniauth and Twitter callback gives TypeError

I'm following this tutorial: http://railscasts.com/episodes/235-omniauth-part-1?view=asciicast to get multiple accounts with Omniauth and Devise to work with Rails 3.2.12. After I authenticate with Twitter, it redirects back to ../auth/twitter/callback with the oauth token as parameters and in my Authentication#create action it says,

render :text => request.env["omniauth.auth"].to_yaml

But when the page renders, it says:

TypeError

can't convert nil into String

The stack trace is:

omniauth-twitter (0.0.14) lib/omniauth/strategies/twitter.rb:23:in `+'
omniauth-twitter (0.0.14) lib/omniauth/strategies/twitter.rb:23:in `block in <class:Twitter>'
omniauth (1.1.3) lib/omniauth/strategy.rb:102:in `instance_eval'
omniauth (1.1.3) lib/omniauth/strategy.rb:102:in `block in compile_stack'
omniauth (1.1.3) lib/omniauth/strategy.rb:101:in `each'
omniauth (1.1.3) lib/omniauth/strategy.rb:101:in `inject'
omniauth (1.1.3) lib/omniauth/strategy.rb:101:in `compile_stack'
(eval):7:in `info_stack'
omniauth (1.1.3) lib/omniauth/strategy.rb:315:in `info'
omniauth (1.1.3) lib/omniauth/strategy.rb:328:in `auth_hash'
omniauth (1.1.3) lib/omniauth/strategy.rb:355:in `callback_phase'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:58:in `callback_phase'
omniauth (1.1.3) lib/omniauth/strategy.rb:219:in `callback_call'
omniauth (1.1.3) lib/omniauth/strategy.rb:175:in `call!'
omniauth (1.1.3) lib/omniauth/strategy.rb:157:in `call'
omniauth (1.1.3) lib/omniauth/builder.rb:48:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.12) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.12) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.12) lib/active_support/callbacks.rb:405:in `_run__3143814823160835356__call__2946912839493394460__callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.12) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.12) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.12) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.12) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.12) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.12) lib/rails/engine.rb:479:in `call'
railties (3.2.12) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.12) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/Users/ashley/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/ashley/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/ashley/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

What can I do to fix this? I don't know where to begin or what's wrong.

Upvotes: 0

Views: 1149

Answers (3)

suhovius
suhovius

Reputation: 426

I had the same problem. Fixed it by updating omniauth-twitter gem

bundle update --source omniauth-twitter

I found this hint here: https://github.com/arunagw/omniauth-twitter/issues/30#issuecomment-19757839

Upvotes: 2

Kushal
Kushal

Reputation: 218

try this out by writing, render :text => env["omniauth.auth"]

this will return hashie mash object in omniauth.auth

Upvotes: 0

muttonlamb
muttonlamb

Reputation: 6501

Rails is telling you that it doesn't have a reference to ["omniauth.auth"], so you are calling to_yaml on a nil object. This is usually a sign that the process that sets up the variable is failing for some reason.

A really awesome way of dealing with these issues is to use better_errors, which opens up a really cool webpage with and interactive console when rails encounters an error (use only in development environment though!

http://railscasts.com/episodes/402-better-errors-railspanel has an awesome guide to doing this.

Upvotes: 2

Related Questions