2016-07-07 95 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