通过Google服务账户创建日历事件时首次收到“未知发件人”通知求助
如何禁用Google Calendar API创建事件时的“未知发件人”通知
我通过Google服务账户调用Calendar API创建日历事件,代码如下:
const auth = new GoogleAuth({ scopes: [ 'https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events' ], keyFile: './src/serviceaccount.json', clientOptions: { subject: 'xxxx@mydomain.com' } }); const calendar = google.calendar({ version: 'v3', auth: auth }); const apiResponse = await calendar.events.insert({ calendarId: "xxxx@mydomain.com", conferenceDataVersion: 1, requestBody: { start: { dateTime: "2024-10-10T08:00:00+09:00", }, end: { dateTime: "2024-10-10T08:30:00+09:00", }, attendees: [{ email: "me@gmail.com" }, { email: "xxxx@mydomain.com" }], summary: 'Test Event', description: 'Test Event created', guestsCanInviteOthers: true, conferenceData: { createRequest: { requestId: randomUUID(), conferenceSolutionKey: { type: 'hangoutsMeet' } } }, reminders: { useDefault: false, overrides: [], }, guestsCanModify: true, visibility: 'default', } });
我尝试设置sendUpdates参数为false来避免收到事件创建通知,但首次执行时仍收到“未知发件人”的通知(截图如下),求解决办法。

解决办法
1. 修正sendUpdates参数的位置与取值
Google Calendar API的sendUpdates是请求顶级参数(不属于requestBody),且接受字符串枚举值而非布尔值。正确写法是传入'none'来完全禁用通知:
const apiResponse = await calendar.events.insert({ calendarId: "xxxx@mydomain.com", conferenceDataVersion: 1, sendUpdates: 'none', // 关键:用'none'替代false requestBody: { // 你的事件内容保持不变 } });
2. 禁用Meet会议的额外通知
由于你创建了Hangouts Meet会议,Meet会独立发送通知,需要在conferenceData.createRequest中添加sendNotifications: false:
conferenceData: { createRequest: { requestId: randomUUID(), conferenceSolutionKey: { type: 'hangoutsMeet' }, sendNotifications: false // 禁用Meet会议通知 } }
3. 检查目标日历的默认通知设置
登录xxxx@mydomain.com的Google日历,进入设置和共享 → 事件通知,关闭所有不需要的默认通知(比如“新事件通知”),避免日历自身触发提醒。
4. 优化参会者配置
如果模拟的用户(xxxx@mydomain.com)是目标日历的所有者,无需将其添加为参会者,这可能触发额外通知,可从attendees数组中移除该邮箱。
内容的提问来源于stack exchange,提问作者mster429
相关产品推荐
相关产品推荐

