Omniauth Facebook 不返回电子邮件和性别 rails 4
Omniauth Facebook not returning email and gender rails 4
我需要从 Facebook 获取姓名、电子邮件、图像和性别。我正在获取姓名和图像,但电子邮件和性别不是从 Facebook 获取的。我在过去的 2 天里苦苦挣扎,谁能帮帮我。
用户模型:
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?
它 returns 一个空值。
即使我检查了我的 Facebook 隐私设置,它也只在 public 个人资料中。谁能帮帮我
添加这些更改以获取数据:
provider :facebook, 'APP_ID', 'APP_SEC_KEY', {:scope => 'email', :info_fields => 'email,name,first_name,last_name,gender', :client_options => { :ssl => { :ca_file => "#{Rails.root}/config/ca-bundle.crt" }}}
您现在需要 user_gender
范围并获得 Facebook 的批准。
然后你可以这样做:
provider(
:facebook,
ENV.fetch("FACEBOOK_APP_ID"),
ENV.fetch("FACEBOOK_APP_SECRET"),
image_size: :large,
secure_image_url: true,
scope: "public_profile,email,user_gender",
info_fields: "email,name,first_name,last_name,gender",
)
我需要从 Facebook 获取姓名、电子邮件、图像和性别。我正在获取姓名和图像,但电子邮件和性别不是从 Facebook 获取的。我在过去的 2 天里苦苦挣扎,谁能帮帮我。
用户模型:
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?
它 returns 一个空值。
即使我检查了我的 Facebook 隐私设置,它也只在 public 个人资料中。谁能帮帮我
添加这些更改以获取数据:
provider :facebook, 'APP_ID', 'APP_SEC_KEY', {:scope => 'email', :info_fields => 'email,name,first_name,last_name,gender', :client_options => { :ssl => { :ca_file => "#{Rails.root}/config/ca-bundle.crt" }}}
您现在需要 user_gender
范围并获得 Facebook 的批准。
然后你可以这样做:
provider(
:facebook,
ENV.fetch("FACEBOOK_APP_ID"),
ENV.fetch("FACEBOOK_APP_SECRET"),
image_size: :large,
secure_image_url: true,
scope: "public_profile,email,user_gender",
info_fields: "email,name,first_name,last_name,gender",
)