How to tell between actual picture vs. default auto-generated image in Google OAuth?
Asked Answered
E

2

6

I'm retrieving user data from Google using the Passport Google Strategy (OAuth 2.0). This works fine except when the logged-in user does not have an explicitly set profile picture. In such cases, Google returns a default image with the user's first-name initial:

enter image description here

I want to be able to tell if the image returned by the API is a real image or something like this. How do I accomplish this? There's a similar question here but the answer is outdated since Google no longer seems to offer an isDefault flag. Nor does it have a consistent URI for the default silhouette because the auto-generated image is different for different users depending on their initials. Is there any alternative flag offered by Google OAuth 2.0 that tells me if the image is an auto-generated one?

Enchanting answered 5/9, 2019 at 15:30 Comment(2)
try checking out this answer: https://mcmap.net/q/1130811/-how-to-check-whether-google-user-39-s-image-is-default-or-uploadedPourparler
I tried to execute the example given here: developers.google.com/people/api/rest/v1/people/… and it did not respond with any value of "DEFAULT" True/false (so I can not tell if this is a default image or an uploade done)Lipfert
C
1

I have encountered the same problem and I have the solution.

Desired situation: To be able to differentiate if the users registered with Google have a profile image other than the default one, the letter.

To be able to differentiate if the account picture is the default one, you can check with:

https://developers.google.com/people/api/rest/v1/people/get
resourceName: people/me 
personFields: photos 

You can test it with the API explorer

enter image description here

If it is the default image, the letter, we will see the following answer. You can see that default: true

{
  "resourceName": "people/---",
  "etag": "%EgQBAy43GgQBAgUHIgx3dW4rZmJQZk5MZz0=",
  "photos": [
    {
      "metadata": {
        "primary": true,
        "source": {
          "type": "PROFILE",
          "id": "---"
        }
      },
      "url": "https://lh3.googleusercontent.com/a/ACg8ocK4KoGPHVXoM4I8Q3OrgagLjudTui7fHEyprLuUIMBuzfwhVQ=s100",
      "default": true
    }
  ]
}

In case it is not the default image, we will not have the default field. Attached is the response that is obtained in this case:

{
  "resourceName": "people/---",
  "etag": "%EgQBAy43GgQBAgUHIgxsRC8yTmZDaENKOD0=",
  "photos": [
    {
      "metadata": {
        "primary": true,
        "source": {
          "type": "PROFILE",
          "id": "---"
        }
      },
      "url": "https://lh3.googleusercontent.com/a/ACg8ocL_xxtSIuAeTBJp4N80rocGcPOEtK5J5sSPdwt1kAbndo=s100"
    }
  ]
}
Chura answered 19/6 at 6:54 Comment(0)
L
0

Unfortunately, as far as I've concluded, since Google+ will be discontinued and people.googleapis has been changed, as of 2023. I haven't found a way to know if the image you receive from Google is default or not.

Long answered 3/2 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.