我在从Facebook注册后访问用户的电子邮件,first_name和last_name时遇到问题。
这是我的Omniauth.rb的样子:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET'],
:scope => 'email',
:info_fields=>'first_name, last_name, email'
end
当Facebook登录窗口显示时,它会正确显示范围("此应用程序可以访问您的电子邮件")。但是当我撬开回应时,我发现我没有得到任何我要求的字段。
{"provider"=>"facebook",
"uid"=>"10101161800900201",
"info"=>
{"name"=>"Jackson Cunningham",
"image"=>"http://graph.facebook.com/10101161800900201/picture"},
"credentials"=>
{"token"=>
"...",
"expires_at"=>1445243073,
"expires"=>true},
"extra"=>
{"raw_info"=>
{"name"=>"Jackson Cunningham", "id"=>"10101161800900201"}}}
答案 0 :(得分:4)
想出来。除了Omniauth.rb之外,您还需要确保编辑Devise.rb
Devise.rb应该有:
config.omniauth :facebook, "your_facebook_id", "your_facebook_secret", scope: 'email,public_profile', info_fields: 'email, first_name, last_name'
替换您需要的任何特定info_fields(所有可用的here列表)