php - PHP 中的 Office 365 API

标签 php azure office365 office365api

我正在尝试为我的公司制作一个日历 View ,以显示哪些员工有空。我在Azure中制作了一个应用程序,我可以登录系统,获得访问 token ,但无法获取信息。

我使用curl构建请求网址并通过我的请求发送此 header

array(6) {
 [0]=>
  string(28) "User-Agent: php-tutorial/1.0"
  [1]=>
  string(588) "Authorization: Bearer ~ACCESS_TOKEN~"
  [2]=>
  string(24) "Accept: application/json"
  [3]=>
  string(55) "client-request-id: ~GUID~"
  [4]=>
  string(30) "return-client-request-id: true"
  [5]=>
  string(45) "X-AnchorMailbox: ~MAIL~"
}

我得到的回应是:“”

我做错了什么?

更新

登录后,Microsoft 不会询问我是否要授予对该应用程序的访问权限,但它会授予我一个访问 token 。这可能是问题所在吗?我怎样才能让它请求许可?

更新2

登录并尝试获取信息后,我收到 401 错误:访问被拒绝。我认为这很奇怪,因为它已经授予了我一个访问 token 。

更新3

几天后,我尝试了一些示例和教程代码来检查它是否有效。但即使在这些应用程序中,API 似乎也不起作用。 这些是我尝试过的项目。

https://github.com/microsoftgraph/php-connect-rest-sample

https://dev.outlook.com/restapi/tutorial/php

最佳答案

根据https://graph.microsoft.io/en-us/docs/overview/errors处的错误列表,当你收到401错误时,这意味着

Required authentication information is either missing or not valid for the resource.

您的访问 token 可能不包含您的应用程序请求的资源的范围。例如

如果你想列出日历 View 的资源,可以引用https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/user_list_calendarview的文档:

One of the following scopes is required to execute this API: Calendars.Read; Calendars.ReadWrite

请登录您的 Azure AD 应用程序的门户,检查 Microsoft Graph拥有对用户日历的完全访问权限读取用户日历权限是否已标记。

您可以使用访问 token 检查响应正文的“范围”部分,请参阅https://azure.microsoft.com/en-us/documentation/articles/active-directory-protocols-oauth-code/#use-the-authorization-code-to-request-an-access-token了解更多信息。

关于php - PHP 中的 Office 365 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38850437/

相关文章:

java - 在 Office 365 REST API 中对事件使用扩展属性

azure - 使用环境变量配置Azure Function的LogLevel

sharepoint - Office Graph API-从列表中获取项目

javascript - 在 javascript if 语句中使用 php 变量

javascript - 单页结账未继续下一步

Azure Active Directory B2C header 问题

java - 微软 Azure 和 Glassfish

Azure Active Directory 同步工具 - 同步新的 AD,它会清除我在 Azure AD 中的用户吗?

php - 打开带有动态内容的 jQuery UI 对话框

php - 如何修复使用 gmail 发送电子邮件时出现的错误?