繁体   English   中英

从 Microsoft Graph API 获取驱动器的项目:请求格式错误或不正确

[英]Getting the drive's items from Microsoft Graph API: The request is malformed or incorrect

我正在尝试通过 Microsoft Graph Api (SDK) 获取驱动器的项目并尝试了以下选项:

  1. _graphServiceClient.Drives[driveInfo.Id].Items.Request().GetAsync() :不幸的是,这会导致消息错误,消息为“请求格式错误或不正确” ,代码为“invalidRequest” 但是,如果我执行_graphServiceClient.Drives[driveInfo.Id].Request().GetAsync() ,我会取回所有驱动器,但Items属性为null

  2. _graphServiceClient.Drives[driveInfo.Id].Request().Expand(d => d.Items).GetAsync() ,这也会导致错误消息“请求格式错误或不正确”和代码“invalidRequest”

我不知道如何从这里继续,仍在研究中,但目前文档让我一无所知。 任何成功使用.Expand()或从驱动器获取实际文件的人?

谢谢,Y

只有在获取单个DriveItem时才使用Items

await graphClient
  .Me
  .Drive
  .Items[item.Id] 
  .Request()
  .GetAsync();

await graphClient
  .Drives[drive.Id]
  .Items[item.Id]
  .Request()
  .GetAsync();

当您想要检索DriveItem集合时,您需要指定根文件夹:

await graphClient
  .Me
  .Drive
  .Root // <-- this is the root of the drive itself
  .Children // <-- this is the DriveItem collection
  .Request()
  .GetAsync();

await graphClient
  .Drives[drive.Id]
  .Root 
  .Children
  .Request()
  .GetAsync();

SDK 单元测试是快速示例的良好来源。 例如, OneDriveTests.cs包含几个用于寻址 Drives 和 DriveItems 的示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM