简体   繁体   English

并非所有用户都使用 Microsoft.Graph 检索

[英]Not all users are retrieved with Microsoft.Graph

I need to retrieved from Azure Active Directory all members (users) of a group, including those within nested groups.我需要从 Azure Active Directory 中检索组的所有成员(用户),包括嵌套组中的成员。 Here is my code:这是我的代码:

        ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication);

        GraphServiceClient graphServiceClient = new GraphServiceClient(authenticationProvider);

        IGroupTransitiveMembersCollectionWithReferencesPage members = await graphServiceClient.Groups["{myGroupId"]  
            .TransitiveMembers
            .Request()
            .GetAsync();

        List<string> repEmails = members.OfType<User>().Select(member => $"{member.DisplayName} <{member.Mail}>").ToList();

This does retrieve the data, but today I realized that some of the users are missing in my list of results.这确实检索了数据,但今天我意识到我的结果列表中缺少一些用户。 Am I missing something, or is there any limitations on how many users can be retrieved?我是否遗漏了什么,或者对可以检索的用户数量有任何限制?

PS I found the following elsewhere in StackOverflow: PS我在StackOverflow的其他地方发现了以下内容:

Please note that it might not return all the users if there are too many.请注意,如果用户太多,它可能不会返回所有用户。 In that case you will get uri with nextLink to get next batch of results.在这种情况下,您将通过 nextLink 获得 uri 以获取下一批结果。

Can I get a sample on how this can be done?我可以得到一个关于如何做到这一点的样本吗?

All Graph requests, which return a collection (like users, groups, etc.) are put into an collection object that is (within C#) named with Page at the end of the class name.返回集合(如用户、组等)的所有 Graph 请求都放入一个集合对象中,该对象(在 C# 中)以类名末尾的Page命名。

So you only get the first n element back.所以你只能得到第一个 n 元素。 You can set the desired value through the $top query parameter (or in C# with .Top(x) ).您可以通过$top查询参数(或在 C# 中使用.Top(x) )设置所需的值。 But be aware that the maximum allowed value can vary depending on the kind of collection you're going to ask.但请注意,最大允许值可能因您要询问的集合类型而异。 Most of them have a maximum value of 999, but a few have lower values (If you pick a too high number you get back an error message containing the maximum allowed value).它们中的大多数的最大值为 999,但也有一些具有较低的值(如果您选择的数字太大,则会返回包含最大允许值的错误消息)。

The retrieved page object has a property NextPageRequest which will be not null, if further data is available and you can get it by calling it:检索到的页面对象有一个属性NextPageRequest ,如果有更多数据可用,并且您可以通过调用它来获取它,该属性将不为 null:

var moreMembers = await members.NextPageRequest.GetAsync();

You can do this in a while loop, till the property NextPageRequest is null to get a list of all members.您可以在 while 循环中执行此操作,直到NextPageRequest属性为null以获取所有成员的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM