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

4

14

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?

Peplos answered 23/10, 2010 at 13:55 Comment(0)
G
13

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

Godship answered 4/3, 2011 at 21:40 Comment(0)
G
12

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>");
    
Gridiron answered 23/10, 2012 at 16:49 Comment(2)
Thanks a lot.Can you tell me how you came to know about the cache fix part?Wenonawenonah
I tested it with multiple accounts.Gridiron
I
1

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

Incensory answered 3/3, 2011 at 17:24 Comment(5)
could not get the xml file. it's saying not found all the timePeplos
Sorry, I didn't notice that [your google account name] part disappeared because I was using HTML tag syntax. I corrected my answer. Please try again.Incensory
What is [your google account name] in this context? My gmail account is [email protected], which doesn't work, not does firstname.lastname.Motorbus
@Motorbus This won't work any more because Google Buzz is discontinuedIncensory
Thanks @Incensory - it might be worth adding that to your answer.Motorbus
P
0

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.

Photogenic answered 31/7, 2016 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.