How to uniquely identity a Person resource in Google People API response from a particular user?
Asked Answered
W

1

8

Google People API, unlike Google Plus API doesn't provide an unique id for each Person resource in the response.

Why has this been deprecated/removed and how to uniquely identify a Person in an user's contacts list without an id?

Woodwind answered 21/9, 2016 at 5:47 Comment(0)
S
7

In short, use resourceName as an ID.

The Google People API is the user's list of contacts and have IDs specific to the user. They can create contacts that only have a mailing address or only have a name and no contact info. There is no way for Google to logically collate all of these contacts across all of the Google Contacts users.

Specific contacts or a user have a resourceName field that uniquely identifies that resource (contact) for the authenticating user. You basically want to use that as an id. This is the value you for use, for example, to query People.get.

This is part of an example response of a single contact from People.connections:

  {
    "resourceName": "people/103710953423417258027",
    "etag": "qwApd98gduQ=",
    "metadata": {
        "sources": [{
            "type": "CONTACT",
            "id": "1",
            "etag": "#rj+KMFHVyHY="
        }, {
            "type": "PROFILE",
            "id": "103710953423417258027",
            "etag": "#4eZfef/IuMFw="
        }],
        "objectType": "PERSON"
    },
    ...
  }

resourceName is essentially the "id" of that contact and then in the metadata field it lists the sources the contact data comes from. E.g. CONTACT is for a Google Contacts entry where the user has manually entered name/phone/email/etc. PROFILE is a Google Profile, commonly with Google+ data.

The Person resource docs are a great place to learn more about these values.

Stlaurent answered 21/9, 2016 at 15:9 Comment(6)
I am talking about the contact Ids specific to the user. If you go through the Google People API, you won't find any Id field being returned in the response. Is this by design or did they forget to include it?Woodwind
@Woodwind I've updated the answer with info about resourceNameStlaurent
The Person resource docs mention this: The resource name may change when adding or removing fields that link a contact and profile such as a verified email, verified phone number, or profile URL. In that case, we can't use it as an Id for syncing and updation, can we?Woodwind
resourceName and source.id are what you have to work with so ya, you kind of have to use them for syncing.Stlaurent
The personMetadata is supposed to link old and new resourceNames, so you should be able to use it as an ID for syncing as long as you can update IDs. developers.google.com/people/api/rest/v1/people#personmetadataSenegambia
You are right. This is not an OOP this is garbage. I am facing the same problem how to identify user who logged in and it is like a nightmare.Wellmannered

© 2022 - 2024 — McMap. All rights reserved.