使用 Microsoft Graph API 获取更改通知Use the Microsoft Graph API to get change notifications

命名空间:microsoft.graphNamespace: microsoft.graph

Microsoft Graph REST API 使用 Webhook 机制将更改通知传递到客户端。The Microsoft Graph REST API uses a webhook mechanism to deliver change notifications to clients. 客户端是一个 Web 服务,用于配置自身的 URL 以接收通知。A client is a web service that configures its own URL to receive notifications. 客户端应用使用通知在更改时更新其状态。Client apps use notifications to update their state upon changes. 有关详细信息(包括如何订阅和处理传入通知),请参阅设置用户数据更改的通知For more details, including how to subscribe to and handle incoming notifications, see Set up notifications for changes in user data.

使用 Microsoft Graph API,应用可以订阅以下资源的更改:Using the Microsoft Graph API, an app can subscribe to changes on the following resources:

资源Resource 支持的资源路径Supported resource paths 可包含在通知中的资源数据Resource data can be included in notifications
Outlook 邮件Outlook message 对用户邮箱中的所有邮件更改:Changes to all messages in a user's mailbox:
/users/{id}/messages
对用户收件箱中的所有邮件更改:Changes to messages in a user's Inbox:
/users/{id}/mailFolders('inbox')/messages
No
Outlook 事件Outlook event 对用户邮箱中的所有事件更改:Changes to all events in a user's mailbox:
/users/{id}/events
No
Outlook 个人联系人Outlook personal contact 对用户邮箱中的所有个人联系人更改:Changes to all personal contacts in a user's mailbox:
/users/{id}/contacts
No
用户user 对所有用户更改:Changes to all users:
/users
对特定用户更改:Changes to a specific user:
/users/{id}
No
group 对所有组更改:Changes to all groups:
/groups
对特定组更改:Changes to a specific group:
/groups/{id}
对特定组的所有者所做的更改:Changes to owners of a specific group:
/groups/{id}/owners
对特定组的成员所做的更改:Changes to members of a specific group:
/groups/{id}/members
No
Microsoft 365 组对话Microsoft 365 group conversation 查看组的对话:Changes to a group's conversations:
groups/{id}/conversations
No
OneDrive(个人版)上的 driveItemdriveItem on OneDrive (personal) 对_任何文件夹_的层次结构内的内容更改:Changes to content within the hierarchy of any folder:
/users/{id}/drive/root
No
OneDrive for Business 上的 driveItemdriveItem on OneDrive for Business 对_根文件夹_的层次结构内的内容更改:Changes to content within the hierarchy of the root folder:
/drives/{id}/root
/users/{id}/drive/root
No
SharePoint [网站][]下的[列表][]list under a SharePoint site _列表_内的内容更改:Changes to content within the list:
/sites/{id}/lists/{id}
No
安全警报Security alert 对特定警报更改:Changes to a specific alert:
/security/alerts/{id}
对已筛选的警报更改:Changes to filtered alerts:
/security/alerts/?$filter
No
团队callRecordTeams callRecord 对_所有_呼叫记录的更改:/communications/callRecordsChanges to all call records: /communications/callRecords No
Teams chatmessageTeams chatmessage 对所有团队中所有频道聊天消息更改:Changes to chat messages in all channels in all teams:
/teams/allMessages
对特定频道中的聊天消息更改:Changes to chat messages in a specific channel:
/teams/{id}/channels/{id}/messages
对所有聊天的消息更改:Changes to chat messages in all chats:
/chats/allMessages
对特定聊天中的消息更改:Changes to chat messages in a specific chat:
/chats/{id}/messages
Yes

注意:以 /users/{id} 开头的任何资源路径还可接受 /me 以引用已登录的用户。Note: Any resource path that begins with /users/{id} can also accept /me to reference the signed-in user.

权限Permissions

通常订阅操作需要拥有对资源的读取权限。In general, subscription operations require read permission to the resource. 例如,若要获取邮件通知,应用需要 Mail.Read 权限。For example, to get notifications for messages, your app needs the Mail.Read permission. 创建订阅一文列出了各个资源类型所需的权限。The create subscription article lists permissions needed for each resource type. 下表列出了将 webhook 用于特定资源类型时应用可以请求的权限类型。The following table lists the types of permissions your app can request to use webhooks for specific resource types.

权限类型Permission type 支持的资源类型Supported resource types
委派 - 工作或学校帐户Delegated - work or school account 警报联系人对话driveItem、[列表][]、 事件邮件用户alert, contact, conversation, driveItem, list, event, group, message, user
委派 - 个人 Microsoft 帐户Delegated - personal Microsoft account 联系人driveItem、[列表][]、事件邮件contact, driveItem, list, event, message
应用程序Application alertcontactlistdriveItemeventgroupmessageusercallRecordalert, contact, list, driveItem, event, group, message, user, callRecord

另请参阅See also