如何接收非通用的 Facebook 个人资料图片?

How to receive non-generic facebook profile pictures?

我现在收到那个个人资料图片,我没有更改我的配置中的任何内容(之前它工作正常,那个用户是我,我有一张个人资料照片)。

# config/initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
  provider(
    :facebook,
    ENV.fetch("FACEBOOK_APP_ID"),
    ENV.fetch("FACEBOOK_APP_SECRET"),
    image_size: :large,
  )
end
# app/controllers/sessions_controller.rb

  def facebook
    uid = auth_hash["uid"]
    email = auth_hash["info"]["email"]
    image_url = auth_hash["info"]["image"]
    name = auth_hash["info"]["name"]
    first_name = name.split.first

    # ...
    attach_image_from_url(@user, image_url)
    # ...
  end

  private

  def auth_hash
    request.env["omniauth.auth"]
  end

  def attach_image_from_url(user, image_url)
    # return if user.image.attached?
    image = Down.download(image_url)
    user.image.attach(io: image, filename: "image.jpg")
  end

我缺少什么吗?

编辑:我尝试将 api 版本设置为 7.0(当时是 4.0),似乎 /picture 端点已经消失 https://developers.facebook.com/docs/graph-api/changelog/version4.0/

升级到 ominauth-facebook 8.0.0(从 7.0.0)并设置 secure_image_url: true 修复了它

Rails.application.config.middleware.use OmniAuth::Builder do
  provider(
    :facebook,
    ENV.fetch("FACEBOOK_APP_ID"),
    ENV.fetch("FACEBOOK_APP_SECRET"),
    image_size: :large,
    secure_image_url: true,
  )
end

没有 secure_image_url: true 我得到一个 500 错误,见 https://github.com/simi/omniauth-facebook/pull/346