Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Users photos API - get the public user photo without authenticating

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?

like image 992
gool Avatar asked Jan 26 '23 21:01

gool


1 Answers

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"
  }
 ]
}
like image 60
Prisoner Avatar answered Feb 04 '23 10:02

Prisoner