首页 > 解决方案 > 有没有办法使用 C# SDK 从 Microsoft Graph API 获取已删除的目录项?

问题描述

有一个文档页面描述了我想要做的确切事情

https://docs.microsoft.com/en-us/graph/api/directory-deleteditems-list?view=graph-rest-1.0&tabs=http

但是,在 C# 中检索此数据的建议方法是

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var group = await graphClient.Directory.DeletedItems
    .Request()
    .GetAsync(); 

由于未指定要查看的项目类型,我尝试使用它并收到错误的请求错误。我似乎找不到在 C# SDK 中指定它的方法。

作为参考,这是它在 Java SDK 中的完成方式

IGroupCollectionPage group = graphClient.directory().deletedItems().microsoft.graph.group()
    .buildRequest()
    .get();

标签: microsoft-graph-apimicrosoft-graph-sdks

解决方案


Github中提出了类似的问题,并将相应地更新您

对于解决方法,您可以使用以下代码

 var deletedGroupReq = await graphClient.Directory.DeletedItems["microsoft.graph.group"]
                        .Request()
                        .Select("DisplayName,DeletedDateTime")
                        .GetAsync();
                    var deletedGroups = graphClient.HttpProvider.Serializer.DeserializeObject<IGraphServiceGroupsCollectionPage>(deletedGroupReq.AdditionalData["value"].ToString());
    
                    Console.WriteLine(JsonConvert.SerializeObject(deletedGroups));

推荐阅读