![](/img/trans.png)
[英]Getting Microsoft Graph Drive items by path using the .NET SDK
[英]Getting the drive's items from Microsoft Graph API: The request is malformed or incorrect
我正在尝试通过 Microsoft Graph Api (SDK) 获取驱动器的项目并尝试了以下选项:
_graphServiceClient.Drives[driveInfo.Id].Items.Request().GetAsync()
:不幸的是,这会导致消息错误,消息为“请求格式错误或不正确” ,代码为“invalidRequest” 。 但是,如果我执行_graphServiceClient.Drives[driveInfo.Id].Request().GetAsync()
,我会取回所有驱动器,但Items
属性为null
。
_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.