我想获得组中所有成员(传递)。 这个电话得到了我想要的东西:
https://graph.microsoft.com/v1.0/groups/{guid}/transitiveMembers/microsoft.graph.user
在C#应用程序中,我使用Graph API SDK。我知道您如何指定queryoptions,但是我需要一个URL段而不是一个查询选项。
此刻我有这个:
graphClient.Groups[guid].TransitiveMembers.Request().Select("id").GetAsync();
这将返回所有成员,但不仅返回用户。因此,如果有人知道如何使用C#SDK来实现这一点,请告诉我。
答案 0 :(得分:0)
提供的请求:
GET https://graph.microsoft.com/v1.0/groups/{group-id}/transitiveMembers/microsoft.graph.user
可以通过msgraph-sdk-dotnet
构造和执行,如下所示:
var requestUrl = $"{graphClient.Groups[groupId].TransitiveMembers.Request().RequestUrl}/microsoft.graph.user";
var message = new HttpRequestMessage(HttpMethod.Get, requestUrl);
await graphClient.AuthenticationProvider.AuthenticateRequestAsync(message);
var response = await graphClient.HttpProvider.SendAsync(message);
,反序列化如下:
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var json = JObject.Parse(content);
var items = json["value"].Where(i => (string)i["@odata.type"] == null);
var members = items.Select(item => item.ToObject<Microsoft.Graph.User>());
foreach (var member in members)
{
Console.WriteLine(member.UserPrincipalName);
}
}
由于查询/groups/{group-id}/transitiveMembers/microsoft.graph.user
仍返回所有可及成员的集合,但仅 检索了microsoft.graph.user
对象的属性,这意味着它不是的工作方式与$filter parameter完全相同,也许更直接的方法是:
a)通过请求检索所有传递成员:
var members = await graphClient.Groups[groupId].TransitiveMembers.Request().GetAsync();
b)并按用户类型过滤:
var userMembers = members.Where(m => m.ODataType == "#microsoft.graph.user").Cast<User>();
foreach (var member in userMembers)
{
Console.WriteLine(member.UserPrincipalName);
}
答案 1 :(得分:0)
此电话:
https://graph.microsoft.com/v1.0/groups/{guid}/transitiveMembers/microsoft.graph.user
Is just loading forever