Yve*_*lpe 2 c# onedrive microsoft-graph-sdks microsoft-graph-api
我正在尝试通过 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()
或从云端硬盘获取实际文件?
谢谢,是
您仅Items
在获取单个时使用DriveItem
:
await graphClient
.Me
.Drive
.Items[item.Id]
.Request()
.GetAsync();
await graphClient
.Drives[drive.Id]
.Items[item.Id]
.Request()
.GetAsync();
Run Code Online (Sandbox Code Playgroud)
当您要检索一个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();
Run Code Online (Sandbox Code Playgroud)
SDK 单元测试是快速示例的良好来源。例如,OneDriveTests.cs
包含几个用于寻址 Drives 和 DriveItems 的示例。