我創建了新的Rails應用程序並安裝了Devise和omniauth-facebook gem。omniauth-facebook無法獲取電子郵件地址
並設置我的Facebook應用程序作爲測試環境。
所以,我通過Facebook登錄並註冊了我的新Rails應用程序,但request.env沒有包含電子郵件address.info。
這個返回request.env [ 'omniauth.auth']
{
"provider" => "facebook",
"uid" => "xxxxxxxxxxxx",
"info" => {
"name" => "xxxxxxx",
"image" => "http://graph.facebook.com/xxx/picture"
},
"credentials" => {
"token" => "tokenstring",
"expires_at" => xxxxxxxxx,
"expires" => true
},
"extra" => {
"raw_info" => {
"name" => "xxx xxxx",
"id" => "xxxxxxxxx"
}
}
}
IT機架request.env [ 'omniauth.auth'] [ '信息'] [ '電子郵件']
我如何通過oauth從facebook獲取電子郵件地址?請任何人幫助我。
滑軌ver是4.2.3 紅寶石ver是2.2.2p95
這是Gem版本
omniauth (1.2.2)
omniauth-facebook (2.0.1)
devise (3.5.1)
配置/初始化/ devise.rb
config.omniauth :facebook, 'appId', 'appSeacret', scope: 'email,public_profile'
應用程序/控制器/ omniauth_callbacks_controller.rb
def all_provider
user = User.from_omniauth(request.env['omniauth.auth'])
if user.persisted?
sign_in_and_redirect user
else
session['devise.user_attributes'] = user.attributes
redirect_to new_user_registration_url
end
end
alias_method :facebook, :all_provider
應用程序/模型/ user.rb
def from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.email = auth.info.email
end
end
添加在2015年7月11日
我重試相同的代碼和我以前測試的Facebook應用程序,並能得到充分的public_profile和電子郵件。
新facebook應用程序是否添加了任何限制?有人知道嗎?
我不工作,我不知道爲什麼,在我的色器件Config中config.omniauth:臉譜,p.key,p.secret,範圍:「電子郵件」,info_fields:「電子郵件,姓名」,但是當試圖讓電子郵件用戶omniauth [:信息] [:電子郵件],這是空 –
同樣的問題存在於我 – Rubyist
這是行不通的。 – Red