gpt4 book ai didi

c# - Microsoft.Graph 获取一个组的所有用户

转载 作者:行者123 更新时间:2023-11-30 19:53:49 27 4
gpt4 key购买 nike

我正在使用 Microsoft.Graph,我想返回特定组中所有用户的列表。我找不到关于此的任何易于理解的信息。

我尝试过使用 .Request().Expand(x => x.Members) 但这只会返回 20 个用户。而且它们没有分页(参见 here )。

我可以很好地提取组列表,但如何根据用户所在的组来过滤用户?这就是我到目前为止所得到的...

public async Task Do()
{
var graphClient = new GraphServiceClient(_authProvider);
var groups = await graphClient.Groups.Request().GetAsync();

do
{
foreach (var group in groups)
{
Console.WriteLine($"{group.Id}, {group.DisplayName}");
Console.WriteLine("------");

var filter = $""; // What goes here?
var users = await graphClient.Users.Request().Filter(filter).GetAsync();

do
{
foreach (var user in users)
{
Console.WriteLine($"{user.Id}, {user.GivenName} {user.Surname}, {user.MemberOf}");
}
}
while (users.NextPageRequest != null && (users = await users.NextPageRequest.GetAsync()).Count > 0);

Console.WriteLine();
}
}
while (groups.NextPageRequest != null && (groups = await groups.NextPageRequest.GetAsync()).Count > 0);
}

最佳答案

类似这样的东西

public async Task Do()
{
var graphClient = new GraphServiceClient(_authProvider);

var groups = await graphClient.Groups.Request().GetAsync();

do
{
foreach (var group in groups)
{
Console.WriteLine($"{group.Id}, {group.DisplayName}");
Console.WriteLine("------");

var users = await graphClient.Groups[group.Id].Members.Request().GetAsync();

do
{
foreach (var user in users)
{
Console.WriteLine($"{user.Id}");
}
}
while (users.NextPageRequest != null && (users = await users.NextPageRequest.GetAsync()).Count > 0);

Console.WriteLine("------");
Console.WriteLine();
}
}
while (groups.NextPageRequest != null && (groups = await groups.NextPageRequest.GetAsync()).Count > 0);
}

关于c# - Microsoft.Graph 获取一个组的所有用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46299656/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com