Search code examples
google-apigoogle-contacts-apigoogle-photos-apigoogle-people-api

Google People API / Other Contacts - how to get photos of other contacts?


Google forces us to migrate from the deprecated Contacts API over new People API.

They even implemented "Other Contacts" feature in the People API which was so demanded.

But now I'm facing another problem - there is no way to get photos of Other Contacts in the People API.

I was digging into this problem and figured out that it's possible to add photos into the readMask (even though it's not documented):

https://people.googleapis.com/v1/otherContacts?access_token=<...>&readMask=emailAddresses,names,photos

...but it doesn't help, because it returns the default picture with the first letter for all contacts, even for contacts who has a real photo. Like this one: https://lh3.googleusercontent.com/cm/ABXenNkcRSTRZU8PEFQfJtaeEBZnxLgN-UO555npUt1idzcMohoSGuJFfKx0JX2AR6Qp=s100

I tried to add coverPhotos into the readMask but it doesn't let it there.

Then I was checking how old Contacts API formats photo urls and figured out the format:

https://www.google.com/m8/feeds/photos/media/<user-email-address>/<contact-id>

But it has 2 disadvantages:

  • this url has to be requested with access_token
  • it works only if the contact uploaded a custom photo, otherwise it returns error

So here is my question:

Is there any simpler and cleaner way to get real photos of Other Contacts in People API?


Solution

  • This bug has been solved and now we have a solution!

    Updated documentation: https://developers.google.com/people/api/rest/v1/otherContacts/list

    There is a new sources[] request parameter. To get the real photos of "other contacts" you need to specify 2 values: READ_SOURCE_TYPE_CONTACT and READ_SOURCE_TYPE_PROFILE.

    The request would look like this:

    GET https://people.googleapis.com/v1/otherContacts?readMask=photos&key=API_KEY&sources=READ_SOURCE_TYPE_CONTACT&sources=READ_SOURCE_TYPE_PROFILE
    

    Now some contacts will contain 2 entries in the photos array:

    photos: [
      {
        metadata: {
          primary: true,
          source: {
            type: "PROFILE",
            id: "11111"
          }
        },
        url: "<THIS IS THE REAL PROFILE PICTURE>"
      },
      {
        metadata: {
          source: {
            type: "OTHER_CONTACT",
            id: "6666666"
          }
        },
        url: "<THIS IS THE DEFAULT PHOTO STUB>",
        default: true
      }
    ]