#!/usr/bin/env python3 """Test Google Calendar API access with the service account.""" import json import os import sys from google.oauth2 import service_account from googleapiclient.discovery import build SERVICE_ACCOUNT_FILE = os.path.expanduser("~/.openclaw/secrets/gcal-service-account.json") SCOPES = ["https://www.googleapis.com/auth/calendar"] creds = service_account.Credentials.from_service_account_file( SERVICE_ACCOUNT_FILE, scopes=SCOPES ) service = build("calendar", "v3", credentials=creds) # List all calendars the service account can access try: calendar_list = service.calendarList().list().execute() calendars = calendar_list.get("items", []) if not calendars: print("No calendars found. You need to share the family calendar with:") print(" family-calendar-sync@hoffmann-family-manager.iam.gserviceaccount.com") print("\nSteps:") print(" 1. Open the family calendar settings in Gmail") print(" 2. Share it with the service account email above") print(" 3. Grant 'Make changes to events' permission") else: for cal in calendars: print(f" {cal['id']} — {cal.get('summary', 'unnamed')} (access: {cal.get('accessRole', '?')})") except Exception as e: print(f"Error: {e}") sys.exit(1)