omn​​iauth-facebook回调方法导致Facebook App Not Setup错误

时间:2014-09-07 01:57:28

标签: ruby-on-rails devise omniauth omniauth-facebook

我正在尝试使用omniauth-facebook gem对我的Rails 4.0.1应用程序实施Facebook身份验证。这是我用来帮助我完成此任务的指南https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

我已按照所有说明操作,我收到了Facebook错误消息。我认为错误来自处理facebook omniauth回调的方法之一。

Facebook显示的错误是 “应用程序未设置:此应用程序的开发人员尚未正确设置此应用程序以进行Facebook登录”

omniauth_callbacks_controller.rb

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

user.rb

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable, :confirmable,
     :omniauthable, :omniauth_providers => [:facebook]

def self.new_with_session(params, session)
   super.tap do |user|
      if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
        user.email = data["email"] if user.email.blank?
      end
    end
 end

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.profile_name = auth.info.name   # assuming the user model has a name
  end
end


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

end

当我第一次从OmniAuth概述页面完成指南时,它有效。我用个人Facebook注册了我的申请。我的帐户成功登录了。当我开始注册其他Facebook帐户时,它崩溃了,我收到了“App Not Setup”错误。

在此先感谢,非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

我们遇到了同样的问题并在此找到了答案:

“在测试您的应用时,请将它们置于开发模式。这会完全隐藏您未在App Dashboard中授权的所有用户查看应用,以了解下面描述的角色。请注意,当您的应用是在开发模式下,您无法代表无法看到您应用的用户呼叫任何API调用。“ Facebook App Security Guidelines

解决方案是通过转到facebook开发人员面板并在角色部分添加它们,以管理员,开发人员或测试人员的身份添加您要测试的其他帐户。