Ruby on Rails Omniauth facebook doesn't return email

后端 未结 5 999
广开言路
广开言路 2020-12-19 06:07

I have been trying for days to setup my Omniauth for facebook I don\'t know what am I doing wrong.

I am not able to get the email of the user. The returned hash only

相关标签:
5条回答
  • 2020-12-19 06:43

    Make sure you don't put spaces in the info-field request (another answer probably typo'ed this).

    You need to specifically ask for email to be returned from the info field hash as it isn't by default.

    If you're using Omniauth-Facebook without Devise, set this up in your config/initializers/omniauth.rb file like so:

    Rails.application.config.middleware.use OmniAuth::Builder do
      provider :facebook, Rails.application.secrets.omniauth_provider_key, Rails.application.secrets.omniauth_provider_secret,
      :scope => 'email', :display => 'popup', :info_fields => 'name,email'
    end
    

    This info is kind of hidden at the very end of the Configuring section on the omniauth-facebook gem's GitHub readme.

    With Devise plus Omniauth, however, you set it in config/initializers/devise.rb like so (no spaces in the string!):

    config.omniauth :facebook, 'app_id', 'app_secret',  scope: 'email', info_fields: 'name,email'
    
    0 讨论(0)
  • 2020-12-19 06:44

    I had the same problem but it turns out it was a different issue, if you use a client side flow make sure to request the scopes you need on your client:

    FB.login(function(response) {
      // hit API callback endpoint
    }, {scope: 'email'});
    
    0 讨论(0)
  • 2020-12-19 06:47

    You need to request the permissions. For example, to request email, user_birthday and read_stream permissions and display the authentication page in a popup window:

    Rails.application.config.middleware.use OmniAuth::Builder do
      provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'],
           :scope => 'email,user_birthday,read_stream', :display => 'popup'
    end
    

    Please check this Omniauth-facebook if you have any doubts.

    0 讨论(0)
  • 2020-12-19 06:49

    I had the same problem. I made it work updating omniauth and omniauth-facebook gems.

    0 讨论(0)
  • 2020-12-19 06:58

    I only got to retrieve the email by adding this in devise.rb:

      config.omniauth :facebook, "KEY", "SECRET", scope: 'email', info_fields: 'email, name'
    
    0 讨论(0)
提交回复
热议问题