I need to fetch name, email, image and gender from facebook. I am getting name and image, but email and gender is not fetched from facebook. I am struggling for past 2 days, can anyone help me out here.
User model:
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.email = auth.info.email
user.gender = auth.extra.raw_info.gender #if user.gender.blank?
user.image = auth.info.image
user.save!
end
end
Omniauth.rb
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
if Rails.env.production?
provider :facebook, '1186046461411581', 'ad1a6702b3e1c572e2b6c7c89b232c13'
elsif Rails.env.development?
provider :facebook, '1186046461411581', 'ad1a6702b3e1c572e2b6c7c89b232c13', {:scope => 'publish_actions,email', :client_options => { :ssl => { :ca_file => "#{Rails.root}/config/ca-bundle.crt" }}}
else
provider :facebook, '1186046461411581', 'ad1a6702b3e1c572e2b6c7c89b232c13'
end
end
If I use user.gender = auth.extra.raw.gender if user.gender.blank?
it returns a null.
Even I have checked with my facebook privacy settings it is in public profiles only. Can anyone please help me out here
Aucun commentaire:
Enregistrer un commentaire