问题
I want get the user profile large or normal picture from facebook. Now I get the square version from user profile picture with this code:
:image => access_token.info.image
# http://graph.facebook.com/id/picture?type=square
How can I get the large or normal versions?
Or and the app, How can I replace in this url the last word, large instead square...
Thank you very much!
回答1:
Below are the 4 Different Size of profile pictures that is allowed by facebook.
http://graph.facebook.com/id/picture?type=small
http://graph.facebook.com/id/picture?type=square
http://graph.facebook.com/id/picture?type=large
http://graph.facebook.com/id/picture?type=normal
回答2:
If you want to grab a different size picture at login time, the omniauth-facebook strategy has an option to change which picture is requested.
image_size: Set the size for the returned image url in the auth hash.
For example, the large picture would be requested in omniauth.rb this way:
provider :facebook, 'secrets', 'sekrets', :image_size => 'large'
https://github.com/mkdynamic/omniauth-facebook#configuring
回答3:
When you save it into the DB you could do it like this access_token.info.image.split("=")[0] << "=large"
and just change large to whatever size you want.
Or you could have a helper method for displaying different sizes in your views.
def profile_photo(type="large")
puts @user.image.split("=")[0] << "=#{type}"
end
profile_photo("small") #=> http://url?type=small
profile_photo("square") #=> http://url?type=square
profile_photo #=> http://url?type=large
profile_photo("normal") #=> http://url?type=normal
回答4:
Instead of changing the config file i just added + "?type=large"
to the url.
<%= image_tag current_user.image + "?type=large" %>
so you can request different sizes of it at any time.
<%= image_tag current_user.image + "?type=normal" %>
<%= image_tag current_user.image + "?type=small" %>
来源:https://stackoverflow.com/questions/10532425/get-user-profile-large-picture-from-facebook-with-omniauth-in-devise-2-0