You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Outlook日历创建会议时通过Microsoft Graph API获取告警

解决Outlook日历会议创建的API订阅问题

核心结论

通过Microsoft Graph订阅(Webhook)接收会议创建通知是正确方案,但你需要调整资源路径和权限类型来解决当前错误。

错误原因分析

你遇到的"/me request is only valid with delegated authentication flow"错误,是因为当前使用的是**应用权限(客户端凭证流)获取的令牌,但/me路径仅支持搭配委托权限(用户登录授权流)**使用。如果你的场景是后台应用级监控(无需用户登录),必须改用users/{userId}替代/me。

正确的订阅配置

根据你的监控场景,分两种情况调整:

1. 单个用户授权监控自身日历(委托权限场景)

如果是用户登录授权后监控自己的日历,使用/me/events作为资源,需申请Calendars.Read委托权限:

curl --location --request POST "https://graph.microsoft.com/v1.0/subscriptions" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer {delegated-token}" \
--data-raw '{
  "changeType": "created",
  "notificationUrl": "{webhook URL}",
  "resource": "me/events",
  "expirationDateTime": "2025-02-20T18:23:45Z",
  "clientState": "your-random-secret-string"
}'

注意:订阅过期时间不能超过Graph API限制的最大值(当前v1.0版本最多7天,需定期续订)

2. 后台应用监控指定用户日历(应用权限场景)

如果是无需用户登录的后台应用,监控特定用户的日历,使用users/{userId}/events作为资源,需申请Calendars.Read应用权限:

curl --location --request POST "https://graph.microsoft.com/v1.0/subscriptions" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer {application-token}" \
--data-raw '{
  "changeType": "created",
  "notificationUrl": "{webhook URL}",
  "resource": "users/{userId}/events",
  "expirationDateTime": "2025-02-20T18:23:45Z",
  "clientState": "your-random-secret-string"
}'

替换{userId}为目标用户的ID或用户主体名称(UPN)

关键注意事项

  • 资源选择:events包含所有日历会议(普通会议和Teams在线会议),若仅需监控在线会议,可使用users/{userId}/onlineMeetings(需匹配对应权限类型)
  • 订阅验证:创建订阅时,Graph会向你的notificationUrl发送验证请求,必须正确返回验证令牌才能完成订阅创建
  • 权限配置:确保已在Azure AD应用注册中添加并授予对应权限,应用权限需要管理员同意

内容的提问来源于stack exchange,提问作者Jay Lin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 19:54:55