【发布时间】:2021-10-31 21:15:14
【问题描述】:
我有两个用于测试的 Google 工作区帐户。账户 A 有一个服务账户,在账户 B 中,我添加了用于域范围委派的服务账户,该账户具有读取/写入账户 B 中日历所需的权限。
阅读事件和日历有效。但是,当尝试使用帐户 B 的资源日历中的服务帐户创建事件时,我收到以下错误:
{"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."}}
添加的权限:
如果我们在一个 Google Workspace 帐户中进行测试,它就可以工作。
这是代码
// 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;
...
【问题讨论】:
-
请编辑您的问题并包含您的代码。请记住,您需要委托给域上的用户。具体如何完成取决于您使用的编程语言。
-
感谢您的反馈,我已经这样做了。
标签: node.js google-api google-calendar-api