我需要从 facebook 获取姓名、电子邮件、图像和性别。我正在获取姓名和图片,但未从 Facebook 获取电子邮件和性别。我在过去的两天里一直在挣扎,有人可以在这里帮助我吗?
用户型号:
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, 'APP_ID', 'APP_SEC'
elsif Rails.env.development?
provider :facebook, 'APP_ID', 'APP_SEC', {:scope => 'publish_actions,email', :client_options => { :ssl => { :ca_file => "#{Rails.root}/config/ca-bundle.crt" }}}
else
provider :facebook, 'APP_ID', 'APP_SEC'
end
end
如果我使用user.gender = auth.extra.raw.gender if user.gender.blank?
它返回一个空值。
即使我已经检查了我的 facebook 隐私设置,它也只在公共个人资料中。任何人都可以在这里帮助我吗