Question

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?

Was it helpful?

Solution

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...

OTHER TIPS

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>");
    

EDIT: This won't work anymore because Google Buzz is discontinued I kept the answer here for historical purposes only.

https://www.googleapis.com/buzz/v1/people/[your google account name]/@self

Yields a XML file. You can then get the contents of < thumbnailUrl > tag, which in turn is the profile thumbnail url.

Please note that the user must be logged in for this to work.

Hope this helps

There is an API provided by http://www.avatarapi.com/ which returns the user's name and profile pic from an email address and based on Google's public info.

It can be called via SOAP or HTTP at this API endpoint: http://www.avatarapi.com/avatar.asmx

One of the benefits of this API is that it does not require the user to be authenticated with Google, however in your case you said the user was already signed in, so this may not apply to you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top