MS Graph API 客户端 - 无法在查询中获得 Expand 功能。

问题描述 投票:0回答:1

我正试图使用图形API扩展MS Teams驱动器(SharePoint文档库)的所有项目。

我可以访问团队(组),但无法直接展开项目集合。如果能做到这一点就更好了,这样我就不需要另一个查询了(性能!)。

根据文档,有$expand=选项,在C#中我有Expand()扩展方法。不幸的是,我找不到任何如何使用它的工作实例。好吧,在官方文档中有一个例子。

 string messageId = "<guid>";
 Message message = await graphClient.Me.Messages[messageId]
            .Request()
            .Expand("attachments")
            .GetAsync();

但我无法成功复制它。属性应该是 "Items",所以我想我应该使用小写的 "Items"(但我也试过用 "Items")。

下面是 teamsDrive当我不会展开任何东西时,你看属性是 "Null"(它应该有项目,文档存在于库中)。

teamDrive
{Microsoft.Graph.Drive}
Activities [IDriveActivitiesCollectionPage]:null
AdditionalData [IDictionary]:Count = 3
Bundles [IDriveBundlesCollectionPage]:null
CreatedBy:{Microsoft.Graph.IdentitySet}
CreatedByUser [User]:null
CreatedDateTime:{30/05/2020 23:46:46 +00:00}
Description [string]:""
DriveType [string]:"documentLibrary"
ETag [string]:null
Following [IDriveFollowingCollectionPage]:null
Id [string]:"b!QXf1ydGT80WWzfKB0A5IvAkI2isDR2NEh9jgSseDzmFpXz0eAriVS6TXSBEiZhVP"
Items [IDriveItemsCollectionPage]:null
LastModifiedBy [IdentitySet]:null
LastModifiedByUser [User]:null

所以,我试了以下方法:

var teamDrive = await graphClient.Groups[group.Id].Drive.Request().Expand("items").GetAsync();

但这给了我一个异常。

Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: invalidRequest
Message: The request is malformed or incorrect.
Inner error:
    AdditionalData:
    request-id: 93ab7efd-0a33-4ff0-800e-d7e95acd8eb4
    date: 2020-06-17T08:41:39
ClientRequestId: 93ab7efd-0a33-4ff0-800e-d7e95acd8eb4

   at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)

我使用的是BETA Graph端点(https:/graph.microsoft.com 使用从 https:/login.microsoftonline.com。{我们的租户Id})与Microsoft.Graph.Beta NuGet包(版本0.18.0-preview-最新版本)。

请注意,我在这个请求中没有使用任何选择或过滤语句,因为其他人已经提到这在扩展时是不允许的。展开和过滤MS Graph API不起作用

c# microsoft-graph microsoft-graph-teams microsoft-graph-groups microsoft365
1个回答
0
投票

好了,我发现我的请求中的错误之处。

Items 只能在我想访问单个项目时使用。当我想访问项目集合(集合中的所有项目)时,我必须展开 Root 驱动器的属性。这 Root 属性,然后有一个 Children 属性,其中包含驱动器根目录下的项目(注意:它不包含文档库的所有项目,只包含顶层文件夹的项目)。

所以基本上,这意味着,我可以使用。

var teamDrive = await graphClient.Groups[group.Id].Drive.Request().Expand(d => d.Root).GetAsync();

然后可以在子项目上迭代。foreach(var childItem in teamDrive.Root.Children) { ... }

下面的帖子帮助我找到了解决方法

© www.soinside.com 2019 - 2024. All rights reserved.