Reputation: 81
I am using rails 3.2.1 omniauth-twitter (0.0.9)
But in twitter callback phase I receive this error :
TypeError "can't convert nil into String"
> omniauth-twitter (0.0.9) lib/omniauth/strategies/twitter.rb:22:in `+'
omniauth-twitter (0.0.9) lib/omniauth/strategies/twitter.rb:22:in `block in <class:Twitter>'
omniauth (1.1.4) lib/omniauth/strategy.rb:106:in `instance_eval'
omniauth (1.1.4) lib/omniauth/strategy.rb:106:in `block in compile_stack'
omniauth (1.1.4) lib/omniauth/strategy.rb:105:in `each'
omniauth (1.1.4) lib/omniauth/strategy.rb:105:in `inject'
omniauth (1.1.4) lib/omniauth/strategy.rb:105:in `compile_stack'
(eval):7:in `info_stack'
omniauth (1.1.4) lib/omniauth/strategy.rb:322:in `info'
omniauth (1.1.4) lib/omniauth/strategy.rb:335:in `auth_hash'
omniauth (1.1.4) lib/omniauth/strategy.rb:362:in `callback_phase'
omniauth-oauth (1.0.1) lib/omniauth/strategies/oauth.rb:58:in `callback_phase'
omniauth (1.1.4) lib/omniauth/strategy.rb:226:in `callback_call'
omniauth (1.1.4) lib/omniauth/strategy.rb:182:in `call!'
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.1.4) lib/omniauth/strategy.rb:184:in `call!'
omniauth (1.1.4) lib/omniauth/strategy.rb:164:in `call'
omniauth (1.1.4) lib/omniauth/builder.rb:49:in `call'
Adding twitter.rb code below :
> require 'omniauth-oauth'
require 'multi_json'
module OmniAuth
module Strategies
class Twitter < OmniAuth::Strategies::OAuth
option :name, 'twitter'
option :client_options, {:authorize_path => '/oauth/authenticate',
:site => 'https://api.twitter.com'}
uid { access_token.params[:user_id] }
info do
{
:nickname => raw_info['screen_name'],
:name => raw_info['name'],
:location => raw_info['location'],
:image => raw_info['profile_image_url'],
:description => raw_info['description'],
:urls => {
'Website' => raw_info['url'],
'Twitter' => 'http://twitter.com/' + raw_info['screen_name'], # 22 line no
}
}
end
extra do
{ :raw_info => raw_info }
end
def raw_info
@raw_info ||= MultiJson.decode(access_token.get('/1/account/verify_credentials.json').body)
rescue ::Errno::ETIMEDOUT
raise ::Timeout::Error
end
alias :old_request_phase :request_phase
def request_phase
screen_name = session['omniauth.params']['screen_name']
if screen_name && !screen_name.empty?
options[:authorize_params] ||= {}
options[:authorize_params].merge!(:force_login => 'true', :screen_name => screen_name)
end
old_request_phase
end
end
end
end
I have already updated omniauth-twitter gem and it remains at the same version mentioned above.
What could be the possible reason?
Upvotes: 2
Views: 4788
Reputation: 5411
Its because raw_info['screen_name']
value is nil and you can not concatenate it with the string.
Replace 'http://twitter.com/' + raw_info['screen_name'], # 22 line no
with
"http://twitter.com/#{raw_info['screen_name']}",
Upvotes: 3