Reputation: 2293
Following this guide, I was able to get a simple authentication system working with Devise and Facebook in my rails app. But for some reason, when a user signs up, i'm able to grab all their info except for their location, bio, website.
Here is what I have in my User model
User.rb
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
user.name = auth.info.name
user.image = auth.info.image
user.location = auth.info.user_location
user.about = auth.info.user_about_me
user.website = auth.info.user_website
end
end
I already added name, image, location, about, website to my user table in my database.
When a user signs up, location, about, website all return nil. How do I get these attributes? Am I calling the wrong methods with auth.info.user_location, auth.info.user_location and auth.info.user_website?
Upvotes: 1
Views: 312
Reputation: 9523
You need to explicitly require the permissions of user_location
, user_about_me
and user_website
when configuring Omniauth-Facebook in config/initializers/devise.rb
, like so:
config.omniauth :facebook, "APP_ID", "APP_SECRET",
scope: 'user_location,user_about_me,user_website'
Also you need to checkout the example Auth Hash from the Omniauth-Facebook gem README to see how the response is going
For more about the permissions, see Facebook Permissions reference page.
Upvotes: 1
Reputation: 1936
The auth hash returns only this much of information. Those extra information which you need can be menioned by mentioning in the scope of the configurations in omniauth.rb
. see the options in the configurations
Upvotes: 0