2

I am migrating our code from Google Contacts API to Google People API as Google Contacts API will be deprecated soon, but I noticed new People APIs are simple to compare with the old Contacts API.

For example, we have below code use the old Contacts API to search in a specific contact Group and were updated after a specific date by passing in the Group and StartDate parameters, but now we can't do the same query with new People API.

My question is in the new People API, is there any way we can search contacts in a specific Group and only get contacts that were updated after a specific date?

I saw one question which uses syncToken, but I think it is not a good solution for us. Option to get the contact entries updated after a specific time NOT given in Google People API

                GData.Contacts.ContactsFeed feed = service.Query(
                    new GData.Contacts.ContactsQuery("https://www.google.com/m8/feeds/contacts/default/full/")
                    {
                        OAuthRequestorId = employeeUserEmail,
                        Group = [contact group url],
                        NumberToRetrieve = FetchSize,
                        StartIndex = 1,
                        StartDate = [a date that only get contacts were modified after it],
                    });
Leon
  • 282
  • 2
  • 10

1 Answers1

0

I think they intentionally moved away from using a timestamp approach (give me all contacts updated since 1/1/2021) to a SyncToken approach.

The SyncToken eliminates any race-condition that might lead to loss of data. For example if a contact was updated while a query was already in progress this leads to a race condition whether that contact would be included in the next query or not, which might cause the data changes to not get synced and next sync would be overridden.

So in case you're doing a fresh sync, or haven't synced for over 7 days, just get all the contacts of a group via: contactGroups.get. If the last sync was less then 7 days ago, use a sync token to get just the updated contacts.

You could potentially get all contacts of a group, and then run a loop that filters via sources.updateTime but again, you're risking data loss.

marmor
  • 27,641
  • 11
  • 107
  • 150
  • Thank you @marmor for your explanation, regarding getting contacts from a specific group, I think we can't get all contacts of a group iva [contactGroups.get](https://developers.google.com/people/api/rest/v1/contactGroups/get) as it doesn't support pagination(only has a `maxMembers` parameter), right? I think we still need to loop all contacts via [people.connections.list](https://developers.google.com/people/api/rest/v1/people.connections/list) to check if the contact in the specific group or not. – Leon May 27 '21 at 14:39
  • just pass 25000 for the maxMembers field and you'll get all members. Google contacts has a top limit of 25,000 contacts so a group can't contain more then that – marmor May 27 '21 at 17:35
  • 1
    25,000 is big enough for most cases, but Google really should expose a `group` parameter on the [people.connections.list](https://developers.google.com/people/api/rest/v1/people.connections/list), that will make things easier – Leon May 28 '21 at 02:31