Leon
Leon

Reputation: 354

Google People API: search contacts in a specific group and contacts updated after a specific time

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],
                    });

Upvotes: 2

Views: 876

Answers (1)

marmor
marmor

Reputation: 28179

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.

Upvotes: 0

Related Questions