我正在尝试为我的公司制作一个日历 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://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/