Hey guys, I’m trying to change my personal Google Calendar using Python in Google Functions. I’ve got some code working that adds an event, and the Google console shows it’s doing something. But I’m not sure which calendar it’s actually changing.
When I put in my personal calendar ID, it throws an error. I thought the service account had all the right permissions. Can I mess with any calendar in my organization using the service account?
Here’s my code:
from google.oauth2 import service_account
from googleapiclient.discovery import build
from datetime import datetime, timedelta
SERVICE_ACCOUNT = 'my_account@example.iam.gserviceaccount.com'
def update_calendar():
creds = service_account.Credentials.from_service_account_file('service_file.json', scopes=['https://www.googleapis.com/auth/calendar'])
delegated_creds = creds.with_subject(SERVICE_ACCOUNT)
cal_service = build('calendar', 'v3', credentials=delegated_creds)
today = datetime.utcnow().date()
next_day = datetime(today.year, today.month, today.day + 1, 9)
start_time = next_day.isoformat()
end_time = (next_day + timedelta(hours=1)).isoformat()
event_details = {
"summary": "Automated Calendar Test",
"description": "Testing Python calendar automation",
"start": {"dateTime": start_time, "timeZone": 'America/New_York'},
"end": {"dateTime": end_time, "timeZone": 'America/New_York'}
}
cal_service.events().insert(calendarId=SERVICE_ACCOUNT, body=event_details).execute()
if __name__ == "__main__":
update_calendar()
It seems to work, but where can I see which calendar I’m actually changing? Any help would be awesome!