我正在使用服务帐户在我们的系统中创建新日历。
index 0
0 2019-12-18 22.63
1 2019-12-19 22.20
2 2019-12-20 21.03
3 2019-12-21 21.03
4 2019-12-22 21.03
5 2019-12-23 17.00
6 2019-12-24 19.65
如上所示,日历被创建为执行calendars.insert调用的服务帐户所拥有。
我还注入了一个calendar.acl记录,我相信该记录授予“电子邮件”标识的用户访问该日历的权限。
在此代码段中,我有:
async function newCalendar (email) {
console.log('creating calendar for username', email, 'as', config.google.calendar.clientEmail);
const auth = await getAuth();
const calendar = google.calendar({version: 'v3', auth});
const newCal = await calendar.calendars.insert({
resource: {summary: `SYSCALENDAR(${email})`}});
const calendarId = newCal.data.id;
const associated = await calendar.acl.insert({
calendarId,
requestBody: {
role: 'reader',
scope: {
type: 'user',
value: email
}
},
sendNotifications: false
});
return calendarId;
}
如果将其设置为true,则用户会收到一封有关新ACL条目的电子邮件,并且可以单击将日历添加到他们自己的calendarList中。
我不希望用户这样做,而是希望将日历作为服务帐户添加到代码中的calendarList中。
这不像calendarList.insert(calendarId)那样简单,因为它将日历插入服务帐户calendarList。
答案 0 :(得分:0)
Google处理由服务帐户创建/修改的日历的方式最近发生了变化。
解决该问题的唯一方法(仅适用于域用户)是Perform G Suite Domain-Wide Delegation of Authority。基本上,使服务帐户代表用户工作,并使服务帐户代表用户接受邀请。