2016-07-07 110 views
1

我使用通过开放ID连接协议获取的访问令牌调用图形api,https://graph.microsoft.com/v1.0/me/drive/root:/foldername时出现以下错误,但是如果我使用相同的令牌获取https://graph.microsoft.com/v1.0/me API,并且我正在搜索的文件夹确实存在于buisness的一个驱动器上,但仍然出现此错误,当我在一段时间后运行相同的代码时,发现它工作正常。可能是什么问题。即使这个api https://graph.microsoft.com/v1.0/me/drive/root/children我得到以下错误。使用微软图形API时404文件未找到错误

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

回答

0

“404未找到文件”的时候,用户不具有办公室365/OneDrive发生错误或有它但尚未初始化OneDrive(即导航到https://[domain]-my.sharepoint.com/personal/)。

一旦用户获得O365/OneDrive并初始化它,您应该能够成功查询https://graph.microsoft.com/v1.0/me/drive/root/children

你也应该能够查询https://graph.microsoft.com/v1.0/me/drive/root:/foldername

如果你确实你要遇到找不到文件夹的合法情况下,您会收到此错误信息:

{ 
    "error": { 
     "code": "itemNotFound", 
     "message": "The resource could not be found.", 
     "innerError": { 
      "request-id": "1ce2bd8d-a88f-42ae-affd-ee90f3c1d4fb", 
      "date": "2016-07-11T03:17:25" 
     } 
    } 
} 
1

如果您最终在这里使用应用专用授权:

this answer中所述,目前仅支持通过Microsoft Graph API访问OneDrive for Business的应用程序授权,并且将丢弃404 FILE NOT FOUND例外。

为了解决这个我用password grant_type流请求令牌:

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