Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding google profile image url when user is logged in using Google's OpenID provider

is there a way to find the the profile image of a user that's logged in using his/her google account (through OpenID).

I've checked stackoverflow and it seems they're using gravatar service to assign an avatar to the email address. but it should be possible to fetch the user google profile image directly from google.

any clue?

like image 969
Allen Bargi Avatar asked Oct 23 '10 13:10

Allen Bargi


2 Answers

It is not possible with OpenId alone. You have two solutions:

  • You don't use the Google picture image, but a picture provided by a third party like Gravatar (it's the simplest way and it's what is used by Stackoverflow);

  • You use the Google Apps Profiles API: see there to retrieve the photo. In that case, the user must be authenticated, for example with the Oauth Protocol: see Google documentation there. If you choose this solution, I suppose you will continue to use OpenId, so you will use both OpenId and Oauth. Google supports an hybrid protocol to simplify this process: the hybrid protocol OpenId+OAuth.

Hope it helps...

like image 147
olivierlemasle Avatar answered Oct 19 '22 23:10

olivierlemasle


UPDATED: currently, that approach not working

I am currently use that approach:

  1. try to load http://profiles.google.com/s2/photos/profile/me?sz=32 (sz is image size)
  2. if load is failed, use dummy google icon
  3. I am also noticed that if after showing avatar I login with another google account, avatar image is still old. To avoid this, I am adding "&cache_fix=" to image url.

    $(".social_avatar")
        .load(function() { $(".social_avatar").css('visibility', 'visible'); })
        .error(function() { $(".social_avatar").attr('src', "/dummy_google_icon.png"); })
        .css('visibility', 'hidden')
        .attr("src", "http://profiles.google.com/s2/photos/profile/me?sz=32&cache_fix=<userid>");
    
like image 39
user1768976 Avatar answered Oct 20 '22 00:10

user1768976