How to get full information about "other contacts" using People API?

Viewed 373

Background

I work on an app that needs to get information of "other contacts" as they appear on the address book page on "Contacts" website of Google:

enter image description here

The problem

The Contacts API is becoming deprecated, and instead we need to use People API.

For this, I use the Java library (here) which makes it easier to reach the various functions.

Sadly, according to the docs (here), querying the list of items from "other contacts" you will get only up to 3 possible fields:

  • emailAddresses
  • names
  • phoneNumbers

Indeed, when using it, that's what I got. I also got fields of "etag" and "resourceName", but that's it. No photos, no cover photos, no nothing else...

The code to do it is very short (after you set everything up) :

val otherContactsResponse =
    otherContacts.list().setReadMask("emailAddresses,names,phoneNumbers")
        .setPageSize(itemsCountToRequest).setPageToken(nextPageToken).execute()
val result=otherContactsResponse.otherContacts

What I've tried

  1. I tried to see if I can query by "reourceName" (example this one), but it seems that "other contacts" are handled differently than normal ones, so this won't work:
result.forEach { personBasic: Person ->
    val test: Person? = peopleService.get(personBasic.resourceName!!)
        .setPersonFields(
            "addresses,ageRanges,birthdays,coverPhotos,emailAddresses,genders,metadata,names,nicknames,occupations,organizations,phoneNumbers,photos,urls")
        .execute()
    Log.d("AppLog", "$test")
}
  1. Sadly there is no similar query for "other contacts" part to search (other than here, which gives you again the same 3 fields).

  2. Tried to find if there are other fields that I missed that could be used somewhere else. I don't even know if resourceName or etag are reliable and unique for querying.

  3. Tried to add more fields to the query, despite the docs talking about just 3 fields. Failed, of course...

  4. There is a function called copyOtherContactToMyContactsGroup (here) which seems that it will copy contacts to the main group of contacts. I guess that if I use this and then query the contacts themselves (not just "other contacts"), I could get the needed information. But this is a waste of time and can pollute the user's address book, even temporarily. I would have to make sure I delete the contacts from there right after I add them...

EDIT: tried this too, and while it seems to work, I don't want to use it as it pollutes the address book with contacts that the users hasn't added. Plus I got sometimes an image which is simply the letter of the person with a background. This is the code of it:

result.firstOrNull { !it.names.isNullOrEmpty()&&!it.emailAddresses.isNullOrEmpty() }?.let { person ->
    val request =
        CopyOtherContactToMyContactsGroupRequest().setCopyMask(
            "emailAddresses,names,phoneNumbers")
            .setReadMask(
                "addresses,ageRanges,birthdays,coverPhotos,emailAddresses,genders,metadata,names,nicknames,occupations,organizations,phoneNumbers,photos,urls")
    val copyResult: Person? =
        services!!.otherContacts.copyOtherContactToMyContactsGroup(
            person.resourceName, request).execute()
    Log.d("AppLog", "success $copyResult")
}

Also, this seems to be extremely slow compared to simple queries, and there is no batch operation for it either. In addition, testing it out, I think it can cause various server issues related to quota being reached (about 180 per minute or so).

I think that as the website shows the photos and can show you per-contact information, we should have this API too, no?

  1. I thought that maybe I could create a new group (label) , copy the "other contacts" to there, and then fetch the information from there (as it allows to get more fields), but the docs (here) say that it was possible before, and not anymore:

The only system contact groups that can have members added are contactGroups/myContacts and contactGroups/starred. Other system contact groups are deprecated and can only have contacts removed.

This is a bit better solution (if it worked) as I can remove groups safely without affecting actual contacts.

The question

What's the best way that I should use in order to get all kinds of information (like normal contacts) about each item in the "other contacts" list? Is it possible without copying to the contacts list and without getting "fake" photos (of the contact initial letter) ?

2 Answers

OK so sadly for now I got a workaround.

First I copy the various fields to a new Person object, one for each of the results of the query, then I add them all using a batchCreateContacts (here, max items per batch is ), and then I deleted them all using batchDeleteContacts (here , max items per batch is 500)

Sadly this still pollutes the address book, but it's much faster than what I've found, and it's quite temporary too.

Weird things I've found :

  1. API usage doesn't seem to show the exact same items as on the website. I know because I tried to find names and emails on the website that I've found from the API but it didn't show them. Even weirder: The count of items seems the same between them
  2. Some items just have names, which is weird because: how did they get there?

"Other" contacts are different from "normal" contacts and have less information available, but why is this? I looked into this a little and found the following:

Save contact info when you interact with people

When you interact with people on Google products, you can automatically save their contact info, including names, email addresses, and phone numbers. When this setting is turned on, you'll keep the contact info for:

People you've shared something with, like a document in Drive
People who share content with you, like shared albums in Google Photos
People included in events or groups you're in

I think that these are the "other" contacts that become a sort of staging ground with minimal collected information.

I have also found that, on the Google Contacts web page that whenever I add information to an "other contact," the contact automatically disappears from the "other" section and appears with the regular contacts.

So, from the web interface, it looks like "other" contacts should only have the minimal information such as name, email address and phone numbers and should be promoted to the regular contact list if information is added/updated. This scenario will explain why "other" contacts are treated differently.

If you are seeing "other" contacts with more than the minimal information, maybe that is the problem.


Update: Well, it turns out that any "normal" contact can be hidden in the web interface and all the information is transferred with the contact to the "other contacts" list, so "other" contacts can have more than the minimal information.

This looks like an unintended state of affairs to me.

Related