मैं अपने रेल आवेदन में ट्विटर लॉगिन सक्षम करने के लिए omniauth-twitter मणि का उपयोग कर रहा हूं। यहाँ मेरी कोड ... है"omniauth-twitter" ईमेल आईडी रेल पर रूबी में ट्विटर से नहीं लाया गया है
gemfile -
gem 'omniauth', '~> 1.1.1'
gem 'omniauth-twitter'
routes.rb -
match '/auth/twitter/callback', to: 'users#twitter_login'
match 'auth/failure', to: 'static_pages#home'
User_controller.rb -
def twitter_login
auth = request.env['omniauth.auth']
authentication = Authentication.find_by_provider_and_uid(auth['provider'],auth['uid'])
if authentication
sign_in authentication.user
redirect_to root_url
else
if(User.where(:email => auth['extra']['raw_info']['email']).exists?)
flash[:notice] = "You already have account in ibetter"
redirect_to root_url
else
user = User.new
user.apply_omniauth(auth)
if user.save(:validate => false)
sign_in user
flash[:notice] = "Welcome to Ginfy"
redirect_to root_url
else
flash[:error] = "Error while creating a user account. Please try again."
redirect_to root_url
end
end
end
end
session_helper.rb -
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
self.current_user = user
end
User.rb मॉडल -
before_save { |user| user.email = email.downcase }
def apply_omniauth(auth)
self.email = auth['extra']['raw_info']['email']
self.name = auth['extra']['raw_info']['name']
authentications.build(:provider => auth['provider'], :uid => auth['uid'], :token => auth['credentials']['token'])
end
ERB कोड -
<%= link_to image_tag("login-twitter.png", alt: "twitter"), "/auth/twitter",:class => "popup", :"data-width" => "600", :"data-height" => "400" %>
ईमेल आईडी चहचहाना से नहीं लाया है। कृपया
मैंने एक समान समस्या को डीबग करने के लिए प्रिये का उपयोग किया। 'Pry' मणि शामिल करें, और फिर ट्विटर से ईमेल आईडी प्राप्त करने की अपेक्षा करने से पहले 'binding.pry' जोड़ें। फिर आप ट्विटर से प्रतिक्रिया का निरीक्षण कर सकते हैं और पता लगा सकते हैं कि क्या हो रहा है। http://yorickpeterse.com/articles/debugging-with-pry/ आपको प्रिये पर शुरू करने में मदद करनी चाहिए। –
आपकी टिप्पणी के लिए धन्यवाद, 'pry' डिबगिंग के लिए भयानक मणि। अब यह इस तरह से दिखता है [1] pry (#)> self.email = auth ['extra'] ['raw_info'] ['ईमेल'] => nil' '[2] pry (# )> स्वयं .name = auth ['extra'] ['raw_info'] ['name'] => "गिन्फी" ' –
SoftwareGeek
[इसे जांचें] (http://stackoverflow.com/questions/3599621/is-there-a-way एक-उपयोगकर्ता-ईमेल-आईडी-बाद-सत्यापन-उसकी-ट्विटर-पहचान-हमें) – SoftwareGeek