Skip to content Skip to sidebar Skip to footer

Get And Display Event Id For Google Calender Api (Python)

I am using the basic quickstart program to test code before adding it to my work project, and I am having trouble with how to retrieve the event ids and display them. Once I manage

Solution 1:

You are using the String eventId where you should have an actual event Id. So you could change your code here from this:

    if not events:
        print('No upcoming events found.')
    for event in events:
        start = event['start'].get('dateTime', event['start'].get('date'))
        print(start, event['summary'])
    event = service.events().get(calendarId='primary', eventId='eventId').execute()

    print(event['summary'])

    #service.events().delete(calendarId='primary', eventId='4qvgpuca08lp3rki5vnuo7qp7r').execute()
if __name__ == '__main__':
    main()

To this:

    if not events:
        print('No upcoming events found.')
    for event in events:
        start = event['start'].get('dateTime', event['start'].get('date'))
        print(start, event['summary'])
        service.events().delete(calendarId='primary', eventId=event['id']).execute()

if __name__ == '__main__':
    main()

This way you are already deleting the events after listing them. Notice the syntax for eventId=event['id']. The id is a property of the Event object. You can see the rest of the properties here.


Post a Comment for "Get And Display Event Id For Google Calender Api (Python)"