ruby-on-railsrubydeviseomniauth-facebook

Rails Omniauth facebook not returning info fields other than default fields


I'm using facebook authentication for my Rails 5 app. I want to fetch user details other than email. But it's not returning the specified fields. Here's my config for 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"
    }

Please help me to get out of this. Thanks in advance.


Solution

  • After checking out the documentation for the omniauth-facebook gem, it seems like you're not getting your extra info fields because you forgot to request the permissions from the users in scope.

    Try adding public_profile to scope, like so:

    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"
    }