Microsoft Graph API是微软提供的一套统一的RESTful API接口,用于访问Microsoft 365服务中的数据,包括Outlook日历、邮件、联系人等功能。
默认情况下,当用户通过Microsoft Graph API创建日历事件时,该用户会自动成为该活动的组织者。要创建当前用户不是组织者的活动,需要特殊处理。
可以通过设置isOrganizer
属性和使用代理发送模式来实现:
POST https://graph.microsoft.com/v1.0/me/calendar/events
Content-Type: application/json
{
"subject": "Team Meeting",
"start": {
"dateTime": "2023-11-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2023-11-15T15:00:00",
"timeZone": "Pacific Standard Time"
},
"attendees": [
{
"emailAddress": {
"address": "realorganizer@example.com",
"name": "Real Organizer"
},
"type": "required"
}
],
"isOrganizer": false,
"organizer": {
"emailAddress": {
"address": "realorganizer@example.com",
"name": "Real Organizer"
}
}
}
Calendars.ReadWrite
应用程序权限(不是委托权限)POST https://graph.microsoft.com/v1.0/users/realorganizer@example.com/calendar/events
Authorization: Bearer [access-token]
Content-Type: application/json
{
"subject": "Team Meeting",
"start": {
"dateTime": "2023-11-15T14:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2023-11-15T15:00:00",
"timeZone": "Pacific Standard Time"
}
}
如果Graph API限制太多,可以考虑使用更底层的EWS API:
// C#示例代码
Appointment appointment = new Appointment(service);
appointment.Subject = "Team Meeting";
appointment.Start = DateTime.Now.AddHours(1);
appointment.End = DateTime.Now.AddHours(2);
appointment.Organizer = new EmailAddress("realorganizer@example.com");
appointment.RequiredAttendees.Add(new Attendee("currentuser@example.com"));
appointment.Save();
这种功能在以下场景中很有用:
如果遇到权限问题:
如果会议仍然将当前用户设为组织者:
没有搜到相关的沙龙