Jackson Cunningham
Jackson Cunningham

Reputation: 5073

Rails: Get user's email after Facebook Oauth (using Devise & facebook omniauth gem)

I'm having trouble accessing a user's email, first_name, and last_name after they signup from Facebook.

Here's what my Omniauth.rb looks like:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET'],
  :scope => 'email',
  :info_fields=>'first_name, last_name, email'
end

When the Facebook login window shows up, it shows the scope properly ("this app will have access to your email"). But when I pry into the response, I see that I'm not getting any of my requested fields back.

   {"provider"=>"facebook",
 "uid"=>"10101161800900201",
 "info"=>
  {"name"=>"Jackson Cunningham",
   "image"=>"http://graph.facebook.com/10101161800900201/picture"},
 "credentials"=>
  {"token"=>
    "...",
   "expires_at"=>1445243073,
   "expires"=>true},
 "extra"=>
  {"raw_info"=>
    {"name"=>"Jackson Cunningham", "id"=>"10101161800900201"}}}

Upvotes: 0

Views: 668

Answers (1)

Jackson Cunningham
Jackson Cunningham

Reputation: 5073

Figured it out. You just need to make sure to edit Devise.rb in addition to Omniauth.rb

Devise.rb should have:

config.omniauth :facebook, "your_facebook_id", "your_facebook_secret", scope: 'email,public_profile', info_fields: 'email, first_name, last_name'

replacing whatever specific info_fields you need (list of all available here)

Upvotes: 4

Related Questions