1

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?

Stalinko
  • 3,319
  • 28
  • 31

2 Answers2

3

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
  }
]
Stalinko
  • 3,319
  • 28
  • 31
  • This is helpful but I'm running into a permissions error for other contact (eg: "Your client does not have permission to get URL"). How did you get around that? – ashemag Mar 14 '22 at 19:42
  • 1
    Ah resolved: add scope "https://www.googleapis.com/auth/userinfo.profile" – ashemag Mar 14 '22 at 19:46
0

The readMask fields accepted for the otherContacts.list method are the following:

  • emailAddresses
  • metadata
  • names
  • phoneNumbers
  • photos

As you can notice, the photos field is an accepted one while making the above request.

However, the returned response should yield a url which redirects you to the user's profile picture. Because of this, I have taken the opportunity to report it on Google's Issue Tracker here. I suggest you star the issue as any updates regarding this will be posted there.

Reference

ale13
  • 5,679
  • 3
  • 10
  • 25
  • Awesome! I marked it too. I have a strong feeling that yesterday in the docs `photos` was absent among accepted values for `readMask` – Stalinko Jul 14 '21 at 18:08