Why wouldn't an API .list() call show events despite me seeing them on the web interface of a calendar?

Viewed 15

A previous question helped me to learn that deleted events in Google Calendar are actually soft-deletes whereas "deleted" events are actually "cancelled" ones. Fair enough.

I now face another problem: for some reason, I cannot anymore .list() events through an API call despite seeing them on the web interface of a calendar. I used to be able to.

This means that repeated sessions of "delete all events" and "add events again" lead to added events just stacking up on the calendar.

enter image description here

Consider the highlighted event called "test entry". You can see there are already four of them. This is how they were created, with an initial attempt to delete everything in the calendar (this is a part of my service that I modified to showcase that specific event being replicated all over again)

# batch container for events addition - it is just one event here
batch_add = service.new_batch_http_request()
entry = {
        "summary": "test entry",
        "start": {
            "dateTime": arrow.now().isoformat(),
        },
        "end": {
            "dateTime": arrow.now().shift(hours=+1).isoformat(),
        },
    } 
batch_add.add(service.events().insert(calendarId=CALENDAR_ID, body=entry))
batch_add.execute()

# by now the event has been successfully added

# delete all existing events from the calendar
# just in case, I am checking for paging, even if the calendar does not have the maximal 200 entries of the batch. As expected, I just have one loop (nextToken is None)
batch = service.new_batch_http_request()
nextToken = None
while True:
    # getting all active events from the calendar. I also tried with showDelete=True
    resp = service.events().list(calendarId=CALENDAR_ID, syncToken = nextToken).execute()
    for l in resp["items"]:
        batch.add(service.events().delete(calendarId=CALENDAR_ID, eventId=l["id"]))
        log.debug(f"delete {l['summary']} on {l['start']['dateTime']} = {l['id']}")
    if not (nextToken := resp.get("nextSyncToken")):
        break
    log.debug(f'nextpageToken: {nextToken}')

batch.execute()

The surprise: resp["items"] is empty!
(this is also the case if I just run a plan resp = service.events().list(calendarId=CALENDAR_ID).execute())

I used to retrieve events from this calendar and now I am lost. I even checked if the calendar I get in resp(resp["summary"]) is the right one (out of despair - and yes, it is the right one).

The weird thing is that resp itself looks good:

{
  "kind": "calendar#events",
  "etag": "\"not-sure-what-this-is-so-I-redacted-it\"",
  "summary": "Martin EDT",
  "updated": "2022-09-13T14:14:29.356Z",
  "timeZone": "Europe/Paris",
  "accessRole": "owner",
  "defaultReminders": [],
  "nextPageToken": "CigKGmlnb3NwNzVtdjQ5NmxocHJyMDdncHNkZ2ljGAEggICApOHR1pkYGg8IABIAGOCTmYv6kfoCIAEiBwgCEMne0ig=",
  "items": []
}

2022-09-13T14:14:29.356Z is indeed the time of the last update: yet another addition of the test event.

0 Answers
Related