使用Microsoft图形API时出现404文件未找到错误

使用Microsoft图形API时出现404文件未找到错误

问题描述:

调用图形API https:时出现以下错误: //graph.microsoft.com/v1.0/me/drive/root:/foldername 使用通过开放ID连接协议获取的访问令牌,但是如果我使用相同的令牌访问 https://graph.microsoft.com/v1.0 /me/drive/root/children 我遇到以下错误.

I am getting following error when calling the graph api, https://graph.microsoft.com/v1.0/me/drive/root:/foldername using the access token got through open id connect protocol, but if i use same token to get to https://graph.microsoft.com/v1.0/me API it works, and the folder which i am searching is really exist on one drive for buisness but still i am getting this error, when i run same code after some time, i found that it works fine. what could be the issue. even for this api https://graph.microsoft.com/v1.0/me/drive/root/children i get following error.

    {
  "error": {
    "code": "UnknownError",
    "message": "404 FILE NOT FOUND",
    "innerError": {
      "request-id": "d7cdf434-ead1-445d-b2be-f269a82027eb",
      "date": "2016-07-07T03:38:47"
    }
  }
}

如果您最终使用仅应用程序授权:

In case you end up here using app-only authorization:

此答案中所述,目前不支持仅应用程序授权才能通过Microsoft Graph API和Microsoft Graph访问OneDrive for Business.会抛出404 FILE NOT FOUND异常.

As mentioned in this answer App-only authorization is currently not supported for accessing OneDrive for Business through Microsoft Graph API and will throw 404 FILE NOT FOUND exceptions.

为解决此问题,我使用了password grant_type流来请求令牌:

To solve this I used the password grant_type flow to request the token:

POST https://login.microsoftonline.com/{tenantId}.onmicrosoft.com/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=password
&username=<username>
&password=<password>
&client_id=<clientId>
&client_secret=<clientSecret>
&resource=https://graph.microsoft.com