I have two google workspace accounts for testing. Account A have a service account and in account B I have added the service account for domain wide delegation with the permissions needed for reading/writing to calendar in account B.
Reading events and calendars works. But when trying to create an event using the service account in the resource calendar in account B I get the following error:
{"error":{"errors":[{"domain":"calendar","reason":"requiredAccessLevel","message":"You need to have writer access to this calendar."}],"code":403,"message":"You need to have writer access to this calendar."}}
Permissions added:
It works if we test within one Google Workspace Account.
This is the code
// clientMail is the service account id
// privateKey is the service account key
// subject is also the service account id
const jwtClient = new google.auth.JWT(
 clientMail,
 undefined,
 privateKey,
 [
 'https://www.googleapis.com/auth/calendar',
 ],
 subject,
 );
 let calendar = google.calendar({
 version: 'v3',
 auth: jwtClient,
 });
...
savedEvent = (await calendar.events.insert({ calendarId, requestBody: event })).data;
...
 - 
 Please edit your question and include your code. Remember that you need to delegate to a user on the domain. How this is done depends on the programming language you are using.Linda Lawton - DaImTo– Linda Lawton - DaImTo2021年09月02日 11:55:22 +00:00Commented Sep 2, 2021 at 11:55
 - 
 Thanks for feedback, I have done so now.Robert– Robert2021年09月02日 12:33:22 +00:00Commented Sep 2, 2021 at 12:33
 - 
 Does this help? stackoverflow.com/a/61932919/11551468Rafa Guillermo– Rafa Guillermo2021年09月02日 13:30:14 +00:00Commented Sep 2, 2021 at 13:30
 
1 Answer 1
You appear to have forgotten to specify which user you want the service account to delegate to.
from google.oauth2 import service_account
SCOPES = ['https://www.googleapis.com/auth/calendar']
SERVICE_ACCOUNT_FILE = '/path/to/service.json'
credentials = service_account.Credentials.from_service_account_file(
 SERVICE_ACCOUNT_FILE, scopes=SCOPES)
delegated_credentials = credentials.with_subject('[email protected]')
 Comments
Explore related questions
See similar questions with these tags.