OmniAuth Facebook与Devise没有返回图像

时间:2016-07-12 15:26:07

标签: ruby-on-rails facebook-graph-api devise omniauth-facebook

我正在尝试使用omniauth-facebook for rails启用Facebook注册/登录。我成功检索了Facebook用户的名字,姓氏和电子邮件。遗憾的是,检索用于创建简档图像的图像并不成功。在config / devise.rb中我有:(做了一些修改)

config.omniauth :facebook, "XXappidXX", "XXsecretXX", callback_url: "http://XXXXXXXX/users/auth/facebook/callback", scope: "public_profile, email", permissions: "public_profile, email", image_size: :large, info_fields: 'email, first_name, last_name, picture'

我的用户类:

class User < ActiveRecord::Base
    def self.from_omniauth(auth)
      where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
        user.email = auth.info.email
        user.first_name = auth.info.first_name
        user.last_name = auth.info.last_name
        user.photo = auth.info.image 
        user.password = Devise.friendly_token[0,20]
      end
    end
    ...

我从localhost获取的insert语句:

 SQL (0.8ms)  INSERT INTO "users" ("provider", "uid", "email", "first_name", "last_name", "photo", "encrypted_password", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id"  [["provider", "facebook"], ["uid", "XXXXXXXX"], ["email", "XXXXXX.com"], ["first_name", "Erik"], ["last_name", "VandeWater"], ["photo", nil], ["encrypted_password", "XXXXXXXXXX"], ["created_at", "2016-07-12 15:07:58.509187"], ["updated_at", "2016-07-12 15:07:58.509187"]]

从OmniAuth返回的哈希:

#<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash expires=true expires_at=1473523053 token="EAAYcrarZAlE8BAKuRypwRSBP2NFrFbzPXPGmJltZAfTmzJVAE68mh54f7r7srsD5uSCJZCzCSZAD7NTtRjC14qLxL95cjbSx0fuiX99999999GtzD0aGAyEE46koakFAnWazXZCYcm9QX74Og6vQQinAqZBLhrj75sK2pGLgZDZD"> extra=#<OmniAuth::AuthHash raw_info=#<OmniAuth::AuthHash email="open_umadgwb_user@tfbnw.net" first_name="Open" id="127279374371632" last_name="User" picture=#<OmniAuth::AuthHash data=#<OmniAuth::AuthHash is_silhouette=false url="https://scontent.xx.fbcdn.net/v/t1.0-1/p50x50/13614986_1999998038_6951825525819638697_n.jpg?oh=1c4e72a136a8c6d12f1bb8106593cf86&oe=582EC4BC">>>> info=#<OmniAuth::AuthHash::InfoHash email="open_umadgwb_user@tfbnw.net" first_name="Open" image="http://graph.facebook.com/127279374371632/picture?type=large" last_name="User"> provider="facebook" uid="127279374371632">

如何从Facebook检索个人资料图片并将其用作用户的照片字段?

1 个答案:

答案 0 :(得分:0)

在选项中使用字符串而不是符号:

config.omniauth :facebook..., image_size: 'large', ...