簡體   English   中英

Microsoft Graph API 查詢可在 Explorer 上運行,但不能在 Microsoft Graph .NET 客戶端庫中運行

[英]Microsoft Graph API Query works on Explorer but not in Microsoft Graph .NET Client Library

我有一個 SharePoint 站點,在 Documents 文件夾中,我有一個 Excel 文件。我想進行特定的 Microsoft Graph 調用,以獲取文件所在位置的詳細信息。 當我在 Graph Explorer 中測試查詢時,這可以按預期工作:

https://graph.microsoft.com/v1.0/sites/b8b6d734-2f94-4070-ae22-xxxxxxxxxxxx/drive/root

當我嘗試使用 Microsoft Graph .NET 客戶端庫在控制台應用程序中使用查詢時,測試查詢執行良好:

var resultPage = await graphClient
  .Sites["b8b6d734-2f94-4070-ae22-xxxxxxxxxxxx"]
  .Drive.Root
  .Request()
  .GetAsync();

當我嘗試select該根目錄中的特定文件夾時,它也適用於圖形資源管理器:

https://graph.microsoft.com/v1.0/sites/b8b6d734-2f94-4070-ae22-xxxxxxxxxxxx/drive/root/children/{foldername}/children/

但是當我在我的應用程序中嘗試同樣的查詢時,它會返回一個錯誤。

編碼:

var resultPage = await graphClient
  .Sites["b8b6d734-2f94-4070-ae22-xxxxxxxxxxxx"]
  .Drive
  .Root
  .Children["foldername"]
  .Children
  .Request()
  .GetAsync();

響應:

Error getting events: 
  Code: itemNotFound
  Message: The resource could not be found.

我也嘗試使用文件夾的id而不是,但這也失敗了。

如果您希望它使用路徑,則需要使用ItemWithPath

var resultPage = await graphClient
  .Sites["b8b6d734-2f94-4070-ae22-xxxxxxxxxxxx"]
  .Drive
  .Root
  .ItemWithPath("/{foldername}")
  .Children
  .Request()
  .GetAsync();

您還可以通過 DriveItem id檢索它,如下所示:

var resultPage = await graphClient
  .Sites["b8b6d734-2f94-4070-ae22-xxxxxxxxxxxx"]
  .Drive
  .Items["{item-id}"]
  .Children
  .Request()
  .GetAsync();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM