Reputation: 15162
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?
Upvotes: 14
Views: 6427
Reputation: 7059
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.
Upvotes: 0
Reputation: 898
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
Upvotes: 1
Reputation: 129
UPDATED: currently, that approach not working
I am currently use that approach:
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>");
Upvotes: 12
Reputation: 1229
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...
Upvotes: 13