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

Rails Omniauth facebook not returning info fields other than default fields

我正在为我的 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"
}