将 Google 日历添加到特定用户日历列表使用服务帐号



我正在使用服务帐户在我们的系统中创建新日历。

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;
}

如上所示,日历创建为由执行 calendars.insert 调用的服务帐户拥有。

我还注入了一个 calendar.acl 记录,我相信该记录授予由"电子邮件"标识的用户访问此日历的权限。

在这个片段中,我有:

sendNotifications: false

如果我将其设置为 true,用户会收到一封有关新 ACL 条目的电子邮件,并且可以单击以将日历添加到他们自己的日历列表中。

我不希望用户必须这样做,而是希望将日历作为服务帐户以代码添加到 calendarList 中。

这不像 calendarList.insert(calendarId( 那么简单,因为它会将日历插入到服务帐户 calendarList 中。

最近,Google 处理由服务帐号创建/修改的日历的方式发生了变化。

未经用户手动批准,无法再将用户添加到此类日历中。

解决此问题的唯一方法(仅适用于网域用户(是执行 G Suite 全网域授权。基本上,使服务帐户代表用户工作,并使服务帐户代表用户接受邀请。

最新更新