在 Graph API 中对组成员查询使用扩展
Using expand on a members of group query in Graph API
我正在尝试构建一个查询,其中我传入一个 groupId 参数,并在 return 中使用 C# 中的 GraphServiceClient 获取所有用户及其组成员资格。
我能够在一个查询中获取用户和组成员身份,并且能够在单独的查询中通过 groupId(但没有组成员身份)获取所有用户。但是我无法将这两个查询合并为一个结果。可能吗?
这是我获取用户及其组成员资格的代码(使用 expand with memberOf):
var users = await _graphServiceClient.Users
.Request()
.Filter(graphFilter) // used for searching on givenName and surname
.Select($"givenName,surname,mail,mobilePhone,id,userPrincipalName")
.Expand(e => e.MemberOf)
.GetAsync();
这里是我获取给定组中用户的代码:
var users = await _graphServiceClient
.Groups[groupId] // Id of the group I want to get users from
.Members
.Request()
.Select($"givenName,surname,mail,mobilePhone,id,userPrincipalName")
//.Expand(e => e.MemberOf) // e is a DirectoryObject, so this does not compile.
//.Expand(e => (e as Microsoft.Graph.User).MemberOf)
//.Expand("memberOf")
.GetAsync();
有什么办法可以解决我的案子吗?我目前正在研究一种新方法,在从 /users 请求时是否可以在过滤器中使用 MemberOf,但我不确定是否可行。
使用以下查询在 Graph Explorer 中执行此操作:
GET https://graph.microsoft.com/v1.0/groups/{groupId}/members/microsoft.graph.user?$expand=memberOf
为类型添加这个特殊参数使用法有点复杂,但可以做到:
var url = serviceClient.Groups[groupId].Members.AppendSegmentToRequestUrl("microsoft.graph.user?$expand=memberOf");
var request = new HttpRequestMessage(HttpMethod.Get, url);
await serviceClient.AuthenticationProvider.AuthenticateRequestAsync(request);
var response = await serviceClient.HttpProvider.SendAsync(request);
我正在尝试构建一个查询,其中我传入一个 groupId 参数,并在 return 中使用 C# 中的 GraphServiceClient 获取所有用户及其组成员资格。
我能够在一个查询中获取用户和组成员身份,并且能够在单独的查询中通过 groupId(但没有组成员身份)获取所有用户。但是我无法将这两个查询合并为一个结果。可能吗?
这是我获取用户及其组成员资格的代码(使用 expand with memberOf):
var users = await _graphServiceClient.Users
.Request()
.Filter(graphFilter) // used for searching on givenName and surname
.Select($"givenName,surname,mail,mobilePhone,id,userPrincipalName")
.Expand(e => e.MemberOf)
.GetAsync();
这里是我获取给定组中用户的代码:
var users = await _graphServiceClient
.Groups[groupId] // Id of the group I want to get users from
.Members
.Request()
.Select($"givenName,surname,mail,mobilePhone,id,userPrincipalName")
//.Expand(e => e.MemberOf) // e is a DirectoryObject, so this does not compile.
//.Expand(e => (e as Microsoft.Graph.User).MemberOf)
//.Expand("memberOf")
.GetAsync();
有什么办法可以解决我的案子吗?我目前正在研究一种新方法,在从 /users 请求时是否可以在过滤器中使用 MemberOf,但我不确定是否可行。
使用以下查询在 Graph Explorer 中执行此操作:
GET https://graph.microsoft.com/v1.0/groups/{groupId}/members/microsoft.graph.user?$expand=memberOf
为类型添加这个特殊参数使用法有点复杂,但可以做到:
var url = serviceClient.Groups[groupId].Members.AppendSegmentToRequestUrl("microsoft.graph.user?$expand=memberOf");
var request = new HttpRequestMessage(HttpMethod.Get, url);
await serviceClient.AuthenticationProvider.AuthenticateRequestAsync(request);
var response = await serviceClient.HttpProvider.SendAsync(request);