Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Access >=1 Google Calendar via the API with service account credentials

Can anyone point me to clear, up-to-date documentation on how to access >=1 Google Calendar with service account credentials?

Most of the Calendar API docs describe using a user's Google account credentials and not a service account. 

After a lot of digging, I was able to cobble together the following:

```
import os
from google.oauth2 import service_account
from googleapiclient.discovery import build

# Path to your service account key file
SERVICE_ACCOUNT_FILE = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]

# Define the scopes
SCOPES = ['https://www.googleapis.com/auth/calendar']

# Authenticate and construct service
credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE, scopes=SCOPES)
service = build('calendar', 'v3', credentials=credentials)

# List available calendards
calendar_list = service.calendarList().list().execute()

# Iterate through calendars and print their details
for calendar in calendar_list.get('items', []):
    print(f"Calendar ID: {calendar['id']}, Calendar Summary: {calendar['summary']}")
```

However, no calendars are printed (`calendar_list.items = []`).

The IT at my organization say that they have added the calendars the service account, but they couldn't really find clear documentation on this task, and had to just guess, to some extent. 

Likely, this is a permissions issue, but how am I supposed to determine what the issue is?

I've tried adding a calendar via the python SDK:
```
service.calendarList().insert(body=calendar_list_entry).execute()
```
as described at https://developers.google.com/calendar/api/v3/reference/calendarList/insert#python, but that results in the following error:
```
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/calendar/v3/users/me/calendarList?alt=json returned "Not Found". Details: "[{'domain': 'global', 'reason': 'notFound', 'message': 'Not Found'}]">
```

Note: the python example at https://developers.google.com/calendar/api/v3/reference/calendarList/insert#python is still Python v2.

0 2 3,806