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

妖精的绣舞 提交于 2020-06-28 04:24:48

问题


I am trying to get a drive's items via the Microsoft Graph Api (SDK) and tried the following options:

  1. _graphServiceClient.Drives[driveInfo.Id].Items.Request().GetAsync():, this unfortunately results in an error with message error with message "The request is malformed or incorrect" and code "invalidRequest". If I execute _graphServiceClient.Drives[driveInfo.Id].Request().GetAsync() however, I get back all drives but the Items property is null.

  2. _graphServiceClient.Drives[driveInfo.Id].Request().Expand(d => d.Items).GetAsync(), this also results in an error with message "The request is malformed or incorrect" and code "invalidRequest".

I don't know how to go on from here, still researching, but the documentation is leaving me clueless at the moment. Anyone success with either .Expand() or getting the actual files from a Drive?

Thanks, Y


回答1:


You only use Items when you're fetching a single DriveItem:

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

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

When you want to retrieve a DriveItem collection, you need to specify the root folder:

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();

The SDK unit tests are a good source for quick examples. For example, OneDriveTests.cs contains several examples for addressing Drives and DriveItems.



来源:https://stackoverflow.com/questions/55940857/getting-the-drives-items-from-microsoft-graph-api-the-request-is-malformed-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!