Rails: Konnte Sie nicht bei Facebook authentifizieren, da "Ungültige Anmeldeinformationen"

Ich habe omniauth-facebook mit integrierthttps://github.com/plataformatec/devise/wiki/OmniAuth%3a-Overview. Aber ich erhalte einen Fehler von:

Could not authenticate you from Facebook because "Invalid credentials".

Und in Protokollen erhalten Sie Folgendes:

Authentication failure! invalid_credentials: OAuth2::Error, : {"error":{"message":"This authorization code has been used.","type":"OAuthException","code":100}}

Ich habe gerät installiert. Wenn ich auf den Facebook-Anmeldelink klicke, kehre ich zu "www.mealnut.com/user/sign_in#" zurück.="und gibt den obigen Fehler aus. Ich habe die Lösung auf" Ungültige Anmeldeinformationen "überprüfthttps://github.com/plataformatec/devise/wiki/OmniAuth%3a-Overview und wie dort erwähnt, ist meine App Header-Set für App-Typ = Web. Ich verstehe nicht, warum es nicht funktioniert.

Auch meine App wird noch von Facebook überprüft. Aber ich glaube nicht, dass es mit diesem Fehler zusammenhängt. Folgendes habe ich für omniauth-facebook getan:

Gemfile enthält:

gem "omniauth", "~> 1.1.4"
gem 'omniauth-facebook', '1.4.1'

Im Benutzermodell hinzugefügt:

devise :omniauthable, :omniauth_providers => [:facebook]
attr_accessible :provider, :uid

  def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
    user = User.where(:provider => auth.provider, :uid => auth.uid).first
    unless user
    user = User.create(name:auth.extra.raw_info.name,
                       provider:auth.provider,
                       uid:auth.uid,
                       email:auth.info.email,
                       password:Devise.friendly_token[0,20]
                      )
  end
user
end

devise.rb

require "omniauth-facebook"
config.omniauth :facebook, "APP_ID", "APP_SECRET", :scope => "offline_access, email" 

omniauth.rb:

OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
 provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], {:provider_ignores_state => true}
end

route.rb:

devise_for: user,: controllers => {: omniauth_callbacks => "omniauth_callbacks"}

Omniauth-Controller:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
    @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

    if @user.persisted?
      sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
      set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end
end

Kann jemand dabei helfen?

Antworten auf die Frage(6)

Ihre Antwort auf die Frage