5

Up until now, we used the Google Plus API to get a user's public photo. All we needed was the user id to get the photo (as described here).

Now that this and the Picasa APIs are being deprecated, the only alternative I found is using the Users.photos API (as described here).

As you can see in the description, this API requires authorization, although the deprecated APIs did not, and the photo I wish to get is public. Not all of our users login with Google, but I want to be able to show everyone the public photos of the users which did login with Google. Is there any way to do this now?

gool
  • 295
  • 5
  • 12
  • How are you planing to search on the user? – Linda Lawton - DaImTo Jan 14 '19 at 10:12
  • I have the user's userId and my app's api key (that should be enough, since that's how it is in Facebook) – gool Jan 14 '19 at 10:14
  • if you have the usersid then you have loged in with the user you use the userinfo endpoint to get their profile picture. – Linda Lawton - DaImTo Jan 14 '19 at 10:15
  • let's say user A authenticated with google, now user B, which is a guest, wants to see the public photo of user A. Then user B is not logged in with Google, therefore cannot see the image. – gool Jan 14 '19 at 10:28
  • Even if user B is logged in they arnt going to be able to get the image for A they dont have access to A. When user A logs in your download user A's image and store it in your system. Then when user B wants to see it you have it. Or save the refresh token for user A and you can then login as A when ever you want and check their image, I suggest a weekly update on users who have not logged in. Check the user info endpoint in my answer easy way to get the image. – Linda Lawton - DaImTo Jan 14 '19 at 10:30
  • I think the point here is the simplicity of using this feature in the current google+ api and now removing it altogether because google is deprecating the apis. They should have given some kind of solution here, like every other platform, giving you access to public information without any authentication. – adi ohaion Jan 14 '19 at 10:54
  • User images are public. You only need to store the URL. If the user granted you `profile` scope, the picture URL is in the ID token, so there is no need to call any endpoint. – pinoyyid Jan 14 '19 at 11:39

1 Answers1

8

You can use the people.get method of the Google People API to get the information you need with just the user ID. While you can get public information without the user's token, you will need an API key. You also won't be able to get the information if it isn't public.

You need to request exactly which fields you want. The "names" and "photos" fields will probably be the ones most important to you, but there are others available. You'll get an array of possible values, each indicating their source. You will probably want the source type of "PROFILE", but you can certainly evaluate others.

So if you issued a request with

GET https://people.googleapis.com/v1/people/101852559274654726533?personFields=names%2Cphotos&key={YOUR_API_KEY}

You'll be asking for my public profile. You'll get back a response something like

{
 "resourceName": "people/101852559274654726533",
 "etag": "%EgYBAj0DNy4aDAECAwQFBgcICQoLDA==",
 "names": [
  {
   "metadata": {
    "primary": true,
    "verified": true,
    "source": {
     "type": "PROFILE",
     "id": "101852559274654726533"
    }
   },
   "displayName": "Allen “Prisoner” Firstenberg",
   "familyName": "Firstenberg",
   "givenName": "Allen",
   "displayNameLastFirst": "Firstenberg, Allen"
  }
 ],
 "photos": [
  {
   "metadata": {
    "primary": true,
    "source": {
     "type": "PROFILE",
     "id": "101852559274654726533"
    }
   },
   "url": "https://lh5.googleusercontent.com/-RDndFau_En4/AAAAAAAAAAI/AAAAAAAB8CY/sTL9kJMmIgk/s100/photo.jpg"
  }
 ]
}
Prisoner
  • 49,922
  • 7
  • 53
  • 105