Office 365 日历 API 使用 EWS 和 OAuth 2

Office 365 Calendar API Using EWS and OAuth 2

请查看底部的编辑内容。

我正在尝试使用 EWS(不是托管 API)与 Office 365 API 一起处理用户日历上的 create/delete/update 事件。

到目前为止,我已经成功地使用 Basic Auth 来验证我的 SOAP 请求是否有效。我现在正尝试用 OAuth 2 替换 Basic Auth。我需要使用客户端凭证流。

以下是我遵循的步骤:

我收到以下错误 (403 Forbidden): The token contains not enough scope to make this call.

我需要做什么来修复这个错误?

编辑 1: 我添加了 Use Exchange Web Services with full access to all mailboxes 应用程序权限,现在发送 SOAP 消息会导致 500 Internal Server Error...

解决方案涉及以下内容:

  1. 添加 Use Exchange Web Services with full access to all mailboxes 应用程序权限,因为 EWS 不允许使用更精细的权限。

  2. 正在为目标邮箱添加一个ExchangeImpersonation SOAP header

  3. 正在设置 X-AnchorMailbox HTTP header。