How to fetch user's profile photo from Google (and not from Google+)?

我们两清 提交于 2019-12-12 06:28:32

问题


Using the Google+ api I am able to fetch all the information about user profile and the way I'm doing it is by calling a GET on the following address:

https://www.googleapis.com/plus/v1/people/11812536713708...432
?key=AIzaSyC_bs...gds353le

Here I'm putting user profile id (google id of the user) and my api key.

Now there are two cases:

1) user set up a google+ profile before and then I'm getting a json file with all necessary data (such as his profile photo, name, etc.)

2) user didn't set up a google+ profile before and then I'm getting json file as follows:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

So in a situation when user doesn't have a google+ account currently I'm unable to fetch his photo. Is there a way of obeying it and somehow fetching his profile details not from google+?

In my ios app I'm using a google sign in feature and they provide a possibility of fetching data for the signed in user (here are some details https://developers.google.com/identity/sign-in/ios/people#retrieving_user_information ) and when I use it and log in to my app with the account that does not have the google+ activated, I'm still able to fetch that user's name, photo, etc. It does not come from google+, in this case it comes from the GIDGoogleUser object. But I can construct this object only when user provides me his username and password.

So is there a way of fetching that data from any Google Api by providing a google user id and api key?


回答1:


Try using:

https://www.googleapis.com/userinfo/v2/me

you can test this using API Explorer. At minimum, your OAuth token needs the profile scope.




回答2:


There is an API provided by http://www.avatarapi.com/ which returns the user's name and profile pic 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, so this could get around your issue where the user does not have a Google+ account.



来源:https://stackoverflow.com/questions/36209983/how-to-fetch-users-profile-photo-from-google-and-not-from-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!