![](/img/trans.png)
[英]Omniauth-Facebook giving error in callback - Email can't be blank?
[英]omniauth-facebook callback methods causes Facebook App Not Setup error
我正在嘗試使用omniauth-facebook gem對我的Rails 4.0.1應用程序實現Facebook身份驗證。 這是我用來幫助我完成此任務的指南, https://github.com/plataformatec/devise/wiki/OmniAuth:-概述
我已按照所有指示進行操作,但出現了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”錯誤。
在此先感謝您的幫助。
我們遇到了同樣的問題,並在這里找到了答案:
“在測試您的應用程序時,請將它們置於開發模式。這將完全隱藏您的應用程序,使其不受您在應用程序儀表板中未授權查看該應用程序的所有用戶的影響,請注意以下所述的角色。 ,則不能代表看不見您的應用的用戶調用任何API調用。” Facebook App安全指南
解決方案是通過轉到Facebook開發人員面板並將其添加到“角色”部分中,以管理員,開發人員或測試人員的身份添加要與之一起測試的其他帳戶。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.