0

so I have the following problem:

I want to manipulate a calendar(my private google calendar) using GoogleFunctions with python backend.I have now followed an code example (which inserts an event) and in the google console it is also shown that a call has taken place. Now I'm just wondering which calendar I'm modifying?

The problem for me is, as soon as I enter the calendarId of my private calendar, the function runs on an error. But actually the service user has all permissions. If I understand it correctly, then I can manipulate all calendars within the organization with the Service user?

So that's my code. It works so far. Now I only ask myself, can I see the calendar I am modifying somewhere?

from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from google.oauth2 import service_account

SUBJECT = 's.........415.iam.gserviceaccount.com'


def main(): 
    
# create credntials 
    credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
    delegated_credentials = credentials.with_subject(SUBJECT)
    
    service = build('calendar', 'v3', credentials=delegated_credentials)

    
    d = datetime.utcnow().date()
    tomorrow = datetime(d.year, d.month, d.day, 10)
    start = tomorrow.isoformat()
    end = (tomorrow).isoformat()
    body={"summary": 'Hello there, Automating calendar', 
      "description": 'Google calendar with python',
      "start": {"dateTime": start, "timeZone": 'Asia/Karachi'}, 
      "end": {"dateTime": end, "timeZone": 'Asia/Karachi'},
     } 

    event = service.events().insert(calendarId=SUBJECT,body=body).execute()


if __name__ == "__main__":
    main()
Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54
Daniel
  • 21
  • 2
  • You're modifying the calendar of your service account, and this isn't viewable in the Calendar user interface. If you want to modify your own calendar, you have to use [domain-wide delegation](https://developers.google.com/admin-sdk/directory/v1/guides/delegation), [provide the necessary scopes for your service account](https://stackoverflow.com/questions/61744176/) and do [impersonate yourself](https://cloud.google.com/iam/docs/impersonating-service-accounts). – Rafa Guillermo Jun 26 '20 at 09:41
  • I'd suggest using [gcsa](https://github.com/kuzmoyev/Google-Calendar-Simple-API) (just a self-plug) – Yevhen Kuzmovych Jul 15 '20 at 14:05

0 Answers0