Search code examples
google-calendar-apigoogle-api-python-client

Find Updated events from Google Watch Push Notification Response


I have created a watch Channel on my calender and I am successfully receiving all updates from Google PUSH Notifcation. But I am not able to use that response to get craeted/updated events. I read few docs and SO questions that I need to use X-Goog-Resource-ID from the response and hit events list API.

But value of this X-Goog-Resource-ID is neither a calender id and neither it is a event id so how can I use this in events list API ?

I am using Python and Service Account for the integration.

Documentaion :

Response from PUSH :

   "X-Goog-Channel-Expiration": "",
    "X-Goog-Channel-ID": "",
    "X-Goog-Channel-Token": "",
    "X-Goog-Message-Number": "",
    "X-Goog-Resource-ID": <resource id>,
    "X-Goog-Resource-State": "exists",
    "X-Goog-Resource-URI": <calender UI>

Google Functions I tried using :

service = build('calendar', 'v3', credentials=credentials)

service.calendars().get(calendarId=X-Goog-Resource-ID).execute()

service.events().list(calendarId=calenderId', eventId=X-Goog-Resource-ID).execute()

Is their any ref Python Example of using digesting Calender PUSH Notification or which API/Function I need to call with what oaarms to get the created/updated events ?


Solution

  • The X-Goog-Resource-ID header holds a value that identifies that particular resource across the APIs. The whole push notifications basically informs you that something has changed on that calendar.

    Now if you want to know exactly what changed, I strongly advise you to perform a synchronisation. One way to do this is to perform a full synchronisation and store the nextSyncToken. Then, when you receive a push notification telling you about a change in the calendar, you only have to use the syncToken to know what has changed since your last synchronisation. You can see a working full example on the linked docs.

    UPDATE

    If you are watching multiple calendars through push notifications, you will need a system in place to track which calendar is being modified at a time. The X-Goog-Resource-ID header maps with the Calendar ID, and it can be used along syncToken to run a events.list() request to receive the updated events.