如何通过Google Calendar API v3仅向新增参会者发送邮件?
解决方案
要实现仅向新增参会者发送邀请通知,你需要使用Google Calendar API的Events.Invite方法,而非Patch或Update。Patch/Update操作的SendUpdates参数没有仅通知新增参会者的选项,而Invite方法正是为这种场景设计的——专门用于添加参会者并仅向新加入的人发送邀请邮件。
以下是修改后的C#代码:
var serviceCredential = GoogleCredential.FromJson(json) .CreateScoped("https://www.googleapis.com/auth/calendar.events") .CreateWithUser("impersonated_user@example.com"); using var calendarService = new CalendarService(new BaseClientService.Initializer { HttpClientInitializer = serviceCredential, ApplicationName = "AppName", }); // 准备新增的参会者列表 var newAttendees = new List<EventAttendee> { new EventAttendee() { DisplayName = "Firstname Lastname", Email = "email@example.com" } }; // 创建Invite请求 var inviteRequest = calendarService.Events.Invite( new Event() { Attendees = newAttendees }, "<calendar_id>", "<event_id>" ); // 执行请求,仅新增参会者会收到通知 inviteRequest.Execute();
关键说明
- Invite方法无需先获取整个事件对象,只需传入要添加的参会者列表即可。
- 该方法会自动处理通知逻辑,仅向新添加的参会者发送邀请,不会打扰已有的参会者,完全匹配Google Calendar UI的操作体验。
- 确保你的服务账号已被授予
https://www.googleapis.com/auth/calendar.events权限,且被 impersonation 的用户拥有该日历事件的编辑权限。
内容的提问来源于stack exchange,提问作者jirkamat
相关产品推荐
相关产品推荐

