People.Connections.List nextSyncToken expires after one week

Viewed 516

I am working on an contact sync solution to be able to keep the contacts in our app in sync with the google contacts of the user.

Our code uses the php library for the google people api latest Version (v1).

Everything is working fine for one week with each user but after that week we get:

400 - Error "Sync token is expired. Clear local cache and retry call without the sync token".

My question now:

Is this intended behaviour that you have to clear all your cache after one week with no changes or am I doing something wrong?

Is there any possibility to renew a syncToken if there were no changes?

I already checked the whole code to be sure that the new received nextSyncToken is saved at our side and used for the next incremental sync request. It seems that the new sync Token is always the same as the one sent in the request. Thus it is just clear that we get that errors if a sync token expires after exactly one week. I also tried to set the option requestSyncToken to true for every list request, even if also a syncToken is set. No success. Sync token stays the same after each request with no changes.

2 Answers

Just in case someone is also facing this problem (syncToken expiration after one week without changes in the persons/contacts list):

Our solution was:

  • Save the creation date and time of a new syncToken each time you get one together with the syncToken.
  • When you receive a syncToken in an incremental sync process compare that token to the stored one. If the syncToken is a new one, overwrite the old one and its creation date/time.
  • Use a continuous process that checks each syncToken. If one is about one week old (for security reasons we used 6 days) create a new syncToken (process see below). As the people API does not offer things like the watch-channels of the calendar API you would anyway need some continuous processes that do list-calls in fixed time intervals for a complete real-time synchronization - so maybe you could combine these tasks depending on your solution for this problem?!

Process for creation of a new SyncToken:

  • Do a new list request without providing a syncToken.
  • For additional security do some checkups like compare the total persons received with the total persons expected by the old/current data. And do this renew process at a time of the day when almost no one does changes generally, for example like 2am.
  • Overwrite the old syncToken and date/time with the new one and the current date/time.

That's it.

But attention! You can still miss some changes that were made if your syncToken renew process is running exactly at the time a change is made!

Create a dummy contact before the sync to get a new syncToken. After the sync delete the dummy contact from both Google Contacts and your cache.

Related