【发布时间】:2015-03-03 16:17:11
【问题描述】:
在花了 30 多个小时试图解决这个问题并搜索了地球的各个角落之后,我在这里发布了我的第一个问题。
无论我尝试什么,我都会得到
'需要参数app_id'
我已经从 https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview 关注文档到 T
以下是我认为最重要的部分……有什么我可能遗漏的想法吗?
config/initializers/devise.rb
config.omniauth :facebook, ENV["FACEBOOK_APP_ID"], ENV["FACEBOOK_APP_SECRET"], scope: 'user'
我已检查系统上的 env 参数是否正确。
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :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.name = auth.info.name # assuming the user model has a name
# user.image = auth.info.image # assuming the user model has an image
end
end
end
【问题讨论】:
-
看起来,
ENV["FACEBOOK_APP_ID"]返回空白或零。只需尝试仔细检查您是否从ENV变量中获取值,尝试在使用前打印它.. -
是的,不知道为什么,如果我从控制台回显 $FACEBOOK_APP_ID 效果很好。
标签: ruby-on-rails ruby facebook devise omniauth