在我的omniauth.rb
中OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, Rails.application.secrets[:facebook_app_id], Rails.application.secrets[:facebook_secret], :scope => 'email,public_profile', :display => 'popup', :info_fields => 'email,public_profile'
end
客户端,javascript:
return FB.login(function(response) {
if (response.authResponse) {
return window.location = '/auth/facebook/callback;
}
}, {scope: 'email,public_profile'});
根据FB API文档。
当FB弹出窗口打开以询问权限时,它会正确地要求发送电子邮件和public_profile。我点击了确定,这只是request.env['omniauth.auth]
仅提供给我的内容:
{ “提供者”: “脸谱”, “UID”: “XXXXXXX”, “信息”:{ “名称”:“XXXXXXX XXXXXXX”, “形象”: “http://graph.facebook.com/XXXXXXX/picture”, “资格证书”:{ “令牌”: “XXXXXXX”, “expires_at”:1444467600, “过期”:真正}, “多余”:{ “raw_info” :{ “名”:“XXXXXXX XXXXXXX”, “ID”: “XXXXXXX”}}}
除了全名和个人资料图片外,我既看不到电子邮件地址,也看不到任何公开信息。
我不知道我做错了什么,因为我完全遵循omniauth-facebook gem的指导方针:https://github.com/mkdynamic/omniauth-facebook以及FB开发者文档。
任何提示?
答案 0 :(得分:1)
你在正确的道路上只需要用你想要从facebook中提取的字段更新信息字段,public_profile将不起作用
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, Rails.application.secrets[:facebook_app_id], Rails.application.secrets[:facebook_secret], :scope => 'email', :display => 'popup', :info_fields => 'email,first_name,last_name'
end