Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get user profile large picture from facebook with omniauth in devise 2.0

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!

like image 279
hyperrjas Avatar asked May 10 '12 10:05

hyperrjas


3 Answers

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

like image 161
Derek Lucas Avatar answered Oct 29 '22 15:10

Derek Lucas


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 
like image 35
vishnu Avatar answered Oct 29 '22 16:10

vishnu


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
like image 25
Justin Avatar answered Oct 29 '22 15:10

Justin