Jordan Haskel
Jordan Haskel

Reputation: 13

Get google calendarID from Google calendar name using API in python

How can I retrieve the calendar ID of various calendars on my google calendar by using the API, I am aware that using the

page_token = None
while True:
  calendar_list = service.calendarList().list(pageToken=page_token).execute()
  for calendar_list_entry in calendar_list['items']:
    print calendar_list_entry['summary']
  page_token = calendar_list.get('nextPageToken')
  if not page_token:
    break

It will return the name but I would like to get it to return the CalendarId

Upvotes: 1

Views: 1561

Answers (1)

rocksteady
rocksteady

Reputation: 2550

google API calendarList resource representation

You could just print out the entry itself, instead of a single key.

page_token = None
while True:
  calendar_list = service.calendarList().list(pageToken=page_token).execute()
  for calendar_list_entry in calendar_list['items']:
    print calendar_list_entry
  page_token = calendar_list.get('nextPageToken')
  if not page_token:
    break

Or directly get the id:

print calendar_list_entry["id"]

Upvotes: 1

Related Questions