Rails Omniauth facebook不返回默认字段以外的信息字段



我正在为我的Rails 5应用程序使用Facebook身份验证。我想获取电子邮件以外的用户详细信息。但它不返回指定的字段。 这是我对 devise.rb 的配置

config.omniauth :facebook, "APP ID", "APP Secret", scope: 'email', secure_image_url: true, :image_size => 'large', auth_type: 'https',info_fields: 'email,name,first_name,last_name,gender',
client_options: {
site: "https://graph.facebook.com/v3.0",
authorize_url: "https://www.facebook.com/v3.0/dialog/oauth"
}

请帮助我摆脱困境。 提前谢谢。

查看了omniauth-facebook gem 的文档后,您似乎没有获得额外的信息字段,因为您忘记向scope中的用户请求权限。

尝试将public_profile添加到scope,如下所示:

config.omniauth :facebook, "APP ID", "APP Secret", scope: 'email,public_profile,user_gender', secure_image_url: true, :image_size => 'large', auth_type: 'https',info_fields: 'email,name,first_name,last_name,gender',
client_options: {
site: "https://graph.facebook.com/v3.0",
authorize_url: "https://www.facebook.com/v3.0/dialog/oauth"
}

最新更新