Dane Iracleous
Dane Iracleous

Reputation: 1759

How do I know if an event was deleted in Google Calendar?

I'm using the Google Calendar API push notifications and I'm successfully receiving the notifications when changes are made to the calendar. However, how can I tell what kind of change it is? When I use my sync token to pull the changes from Google after getting a notification, how do I know whether the event was added, modified, or removed? I don't see any kind of field that specifies this. All I know is which event it is.

Upvotes: 2

Views: 2156

Answers (3)

Samidjo
Samidjo

Reputation: 2355

You have two ways to get deleted events:

In your request :

  1. Specify updatedMin or syncToken.

  2. Or set showDeleted flag to true.

    
    ...

    var request = calendarService.Events.List("Primary");
    
    request.UpdatedMin = DateTime.UtcNow.Date;
    
    //Show deleted events
    request.ShowDeleted = true;
    
    string synchToken = null;
    
    if (string.IsNullOrEmpty(synchToken))
    {
        request.TimeMin = DateTime.UtcNow.Date.AddDays(-1);
    }
    else
    {
        request.SyncToken = calendarStuff.SyncToken;
    }
    
    Events events = request.Execute();
    

Upvotes: 0

david_adler
david_adler

Reputation: 11002

event.status == 'cancelled'

"cancelled" - The event is cancelled (deleted). The list method returns cancelled events only on incremental sync (when syncToken or updatedMin are specified) or if the showDeleted flag is set to true. The get method always returns them

https://developers.google.com/calendar/v3/reference/events

Upvotes: 0

Dane Iracleous
Dane Iracleous

Reputation: 1759

I figured it out - all the fields for a deleted event will be null except its ID (you need some way to identify it).

Upvotes: 1

Related Questions