Rails 3.2.17 Runtime Error Redirection Forbidden facebook

前端 未结 5 746
傲寒
傲寒 2020-12-30 03:56

I have this code I use to get avatars from Facebook...

if auth.info.image.present?
      user.update_attribute(:avatar, URI.parse(auth.info.image))
end
         


        
5条回答
  •  清酒与你
    2020-12-30 04:09

    I actually think the cleanest way of handling this is directly requesting the avatar through https. To do that, just use

    https://graph.facebook.com/672086173/picture?type=square
    

    instead of

    http://graph.facebook.com/672086173/picture?type=square
    

    If you're using omniauth-facebook, you'll need to specify secure_image_url: true in your omniauth initializer to generate that url. Like so:

    config.omniauth :facebook, "XXXX", "XXXX",
                               image_size: { width: 500, height: 500 },
                               secure_image_url: true
    

    Your omniauth initializer should be in your config/initializers directory, probably called omniauth.rb or devise.rb if you're using it together with devise.

提交回复
热议问题