使用 Shrine 获取 FB 个人资料照片

Getting FB profile photo with Shrine

我在我的项目中使用 Devise 进行身份验证,在使用 Shrine 通过 FB 登录时我无法获取图像 gem。

我有标准设计方法从用户模型中的 Omniauth 提供程序获取数据:

  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]
      # Standard version
      user.avatar = auth.info.image
      # For Google:
      # user.avatar_remote_url = auth.info.image
    end
  end

注释行适用于使用 Google 进行记录,并将图像正确设置为 auth.info.image returns link,当粘贴到浏览器中时,会在浏览器。然而,对于 FB,这行代码导致无法持久保存用户 - 在 FB auth.info.image returns a link 的情况下,如果将文件粘贴到浏览器中,它将直接下载到 HDD。

另一方面,标准版在尝试注册时导致错误 809: unexpected token at 'http://graph.facebook.com/v4.0/xxxxxxxxxxx/picture?access_token=xxxxxxxx

在另一个项目中,我成功地以标准方式从 fb 获取图像,但我使用的是回形针。我确实为 Shrine 和用户准备了数据的正确设置(仔细检查它,而且 - 它适用于 Google oauth 和 _remote_url 助手) - 我不确定如何用 Shrine 正确处理从 FB 收到的数据。有什么想法吗?

https://github.com/simi/omniauth-facebook#configuring 下,它声明提供程序的默认配置是 secure_image_url: true,但似乎并非如此。答案是将 secure_image_url: true 添加到我的 Facebook 提供商哈希中,然后它 returns https link 而不是通过 auth.info.image 的 http 可以分配给 user.avatar_remote_url。问题可以关闭了。