Tôi đã tạo ứng dụng Rails mới và cài đặt đá quý Devise và omniauth-facebook.omniauth-facebook cannnot nhận địa chỉ email
Và đặt ứng dụng Facebook của tôi làm môi trường thử nghiệm.
Vì vậy, tôi đã đăng nhập qua facebook và đăng ký ứng dụng Rails mới của tôi, nhưng request.env không chứa địa chỉ email.info.
này request.env được trả lại [ '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"
}
}
}
nó kệ request.env [ 'omniauth.auth'] [ 'thông tin'] [ 'email']
Làm thế nào tôi có thể lấy địa chỉ email từ facebook qua oauth? Xin vui lòng bất cứ ai giúp tôi.
Rails ver là 4.2.3 của Ruby ver là 2.2.2p95
Đây là phiên bản Gem
omniauth (1.2.2)
omniauth-facebook (2.0.1)
devise (3.5.1)
config/initializers/devise.rb
config.omniauth :facebook, 'appId', 'appSeacret', scope: 'email,public_profile'
app/controllers/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
app/models/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
Thêm ít 2015/7/11
tôi thử lại cùng mã với cũ ứng dụng thử nghiệm facebook của tôi, và có thể nhận được public_profile đầy đủ và email.
Có hạn chế nào được thêm cho ứng dụng facebook mới không ?? ai đó biết?
vì tôi không làm việc, tôi không biết tại sao, trong cấu hình của tôi có config.omniauth: facebook, p.key, p.secret, phạm vi: 'email', info_fields: 'email, name' nhưng khi cố gắng để có được người dùng email omniauth [: info] [: email], điều này là trống –
Sự cố tương tự tồn tại đối với tôi – Rubyist
Điều này không hiệu quả. – Red