Takuya
Takuya

Reputation: 21

Using FacebookOmniauth in Rails 5

I'm trying to implement Facebook Authentication and I'm stuck. I exactly followed this guide

https://www.crondose.com/2016/12/guide-integrating-omniauth-rails-5-facebook-login-feature/

and get this error

I, [2017-11-07T00:55:47.114884 #12099] INFO -- omniauth: (facebook) Callback phase initiated. E, [2017-11-07T00:55:47.489634 #12099] ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials: OAuth2::Error, :

Facebook API Version v2.10

I am using ruby 2.4.0 and Rails 5.1.4

Upvotes: 2

Views: 193

Answers (1)

Tom Aranda
Tom Aranda

Reputation: 6026

You are likely getting this error because your App ID or App Secret are incorrect. Make sure your initializer has the correct Facebook API credentials:

# config/initializers/devise.rb
config.omniauth :facebook, <your App Id>, <your App Secret>,
  callback_url: "http://localhost:3000/users/auth/facebook/callback"

Another Tip: Facebook now requires you to specify the fields you want back from Facebook. In other words, if you want the Facebook user's email address, you need to specifically request it. In the past it was returned by default. You can request fields by using the scope parameter in the Devise configuration.

For example, to request the Facebook user's email and name, do this:

# config/initializers/devise.rb
config.omniauth :facebook, <your App Id>, <your App Secret>,
  callback_url: "http://localhost:3000/users/auth/facebook/callback",
  scope: 'email,name'

Upvotes: 0

Related Questions