我正在处理来自http://www.theodinproject.com/ruby-on-rails/final-project的 facebook 克隆项目。
我被omniauth-facebook部分卡住了,我无法成功登录facebook。我认为问题可能是由于 request.env [“omniauth.auth”]。当我尝试提出 request.env["omniauth.auth"].to_yaml. 我得到以下不完整的哈希。它缺少很多信息,例如名字、姓氏、性别等。
--- !ruby/hash:OmniAuth::AuthHash
provider: facebook
uid: '10206926404981253'
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
name: Thomas Pan
image: http://graph.facebook.com/10206926404981253/picture
credentials: !ruby/hash:OmniAuth::AuthHash
token: <token>
expires_at: 1442277104
expires: true
extra: !ruby/hash:OmniAuth::AuthHash
raw_info: !ruby/hash:OmniAuth::AuthHash
name: Thomas Pan
id: <id>
** 为了安全起见,用 <> 替换了一些信息。
我也将它与设计一起使用。
其他一切似乎都设置正确,因为我已按照此处的说明进行设计和omniauth-facebook。https://github.com/plataformatec/devise/wiki/OmniAuth:-概述
用户.rb
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:facebook]
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.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.gender = auth.extra.raw.gender
end
end
设计.rb
config.omniauth :facebook, ENV['FB_APP_ID'], ENV['FB_APP_SECRET']
路线.rb
devise_for :users, :controllers => { :registrations => "users/registrations", :omniauth_callbacks => "users/omniauth-callbacks" }
omniauth_callbacks_controller.rb
def facebook
raise request.env['omniauth.auth'].to_yaml
end
end
任何帮助将不胜感激!
版本信息:Rails 4.2.1 Ruby 2.0.0