命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
获取 组的 直接成员列表。 组可以将用户、联系人、设备、服务主体和其他组作为成员。 此作不可传递。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
GroupMember.Read.All |
Directory.Read.All、Group.Read.All、Group.ReadWrite.All、GroupMember.ReadWrite.All |
委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
应用程序 |
GroupMember.Read.All |
Directory.Read.All、Group.Read.All、Group.ReadWrite.All、GroupMember.ReadWrite.All |
重要
当应用程序查询返回 directoryObject 类型集合的关系时,如果它没有读取特定资源类型的权限,则会返回该类型的成员,但信息有限。 例如,仅返回对象类型和 ID 的 @odata.type 属性,而其他属性则指示为 null
。 通过此行为,应用程序可以请求所需的最低特权权限,而不是依赖于 目录集。*权限。 有关详细信息,请参阅为不可访问的成员对象返回有限的信息。
在委托方案中,还必须为登录用户分配受支持的Microsoft Entra角色或具有 microsoft.directory/groups/members/read
或 microsoft.directory/groups/members/limitedRead
角色权限的自定义角色,或microsoft.directory/groups/hiddenMembers/read
角色权限来读取隐藏成员。 此作支持以下最低特权角色:
- 组所有者
- “成员”用户
- “来宾”用户 - 具有 有限的读取权限
- 目录读取器
- 目录作者
- 组管理员
- 用户管理员 - 包括隐藏成员
- Exchange 管理员 - 包括隐藏成员
- SharePoint 管理员 - 包括隐藏成员
- Intune管理员 - 包括隐藏成员
- Teams 管理员 - 包括隐藏成员
- Yammer 管理员 - 包括隐藏成员
若要列出隐藏成员身份组的成员,还需要 Member.Read.Hidden 权限。
HTTP 请求
GET /groups/{id}/members
可选的查询参数
此方法支持 $filter
、、$count
、$select
、 $search
$top
和 $expand
OData 查询参数,以帮助自定义响应。
- 已启用 OData 强制转换。 例如,
/groups/{id}/members/microsoft.graph.user
检索属于用户的组成员。
-
$search
仅在 displayName 和 description 属性上受支持。
- 默认和最大页面大小分别为 100 个和 999 个组对象。
- 只有高级查询参数支持将查询参数用于此 API(不包括
$expand
)。
$expand
不支持高级查询参数。 有关详细信息,请参阅 目录对象的高级查询功能。
名称 |
说明 |
Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
ConsistencyLevel |
最终。 使用 $search 、$filter 、$orderby 或 OData 强制转换查询参数时,此标头和 $count 是必需的。 它使用的索引可能与对象的最新更改不同步。 |
请求正文
请勿提供此方法的请求正文。
响应
如果成功,此方法在响应正文中返回 200 OK
响应代码和 directoryObject 对象集合。
尝试按表示不受支持的成员类型的 OData 强制转换进行筛选会返回代码错误400 Bad Request
Request_UnsupportedQuery
。 例如, /groups/{id}}/members/microsoft.graph.group
当组为 Microsoft 365 组返回此错误,因为Microsoft 365 组不能将其他组作为成员。
示例
示例1:获取组中的直接成员身份
请求
以下示例显示了一个请求。
GET https://graph.microsoft.com/beta/groups/{id}/members
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].Members.GetAsync();
mgc-beta groups members list --group-id {group-id}
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
//other-imports
)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
members, err := graphClient.Groups().ByGroupId("group-id").Members().Get(context.Background(), nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
DirectoryObjectCollectionResponse result = graphClient.groups().byGroupId("{group-id}").members().get();
const options = {
authProvider,
};
const client = Client.init(options);
let members = await client.api('/groups/{id}/members')
.version('beta')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->groups()->byGroupId('group-id')->members()->get()->wait();
Import-Module Microsoft.Graph.Beta.Groups
Get-MgBetaGroupMember -GroupId $groupId
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
result = await graph_client.groups.by_group_id('group-id').members.get()
响应
以下示例显示了相应的响应。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"value": [
{
"id": "11111111-2222-3333-4444-555555555555",
"mail": "group1@contoso.com",
"mailEnabled": true,
"mailNickname": "Contoso1",
"securityEnabled": true
}
]
}
示例 2:仅获取所有会员资格的计数
请求
以下示例显示了一个请求。
GET https://graph.microsoft.com/beta/groups/{id}/members/$count
ConsistencyLevel: eventual
响应
以下示例显示了相应的响应。
HTTP/1.1 200 OK
Content-type: text/plain
893
示例 3:使用 OData 强制转换获取仅用户会员资格的计数
请求
以下示例显示了一个请求。
GET https://graph.microsoft.com/beta/groups/{id}/members/microsoft.graph.user/$count
ConsistencyLevel: eventual
响应
以下示例显示了相应的响应。
HTTP/1.1 200 OK
Content-type: text/plain
893
示例 4:使用 $search 和 OData 强制转换获取包含字母“Pr”(包括返回对象计数)的显示名称组中的用户成员身份
请求
以下示例显示了一个请求。
GET https://graph.microsoft.com/beta/groups/{id}/members/microsoft.graph.user?$count=true&$orderby=displayName&$search="displayName:Pr"&$select=displayName,id
ConsistencyLevel: eventual
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].Members.GraphUser.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Count = true;
requestConfiguration.QueryParameters.Orderby = new string []{ "displayName" };
requestConfiguration.QueryParameters.Search = "\"displayName:Pr\"";
requestConfiguration.QueryParameters.Select = new string []{ "displayName","id" };
requestConfiguration.Headers.Add("ConsistencyLevel", "eventual");
});
mgc-beta groups members graph-user get --group-id {group-id} --search ""displayName:Pr"" --count "true" --orderby "displayName" --select "displayName,id" --consistency-level "eventual"
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
abstractions "github.com/microsoft/kiota-abstractions-go"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphgroups "github.com/microsoftgraph/msgraph-beta-sdk-go/groups"
//other-imports
)
headers := abstractions.NewRequestHeaders()
headers.Add("ConsistencyLevel", "eventual")
requestCount := true
requestSearch := "\"displayName:Pr\""
requestParameters := &graphgroups.ItemMembersGraph.userRequestBuilderGetQueryParameters{
Count: &requestCount,
Orderby: [] string {"displayName"},
Search: &requestSearch,
Select: [] string {"displayName","id"},
}
configuration := &graphgroups.ItemMembersGraph.userRequestBuilderGetRequestConfiguration{
Headers: headers,
QueryParameters: requestParameters,
}
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphUser, err := graphClient.Groups().ByGroupId("group-id").Members().GraphUser().Get(context.Background(), configuration)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
UserCollectionResponse result = graphClient.groups().byGroupId("{group-id}").members().graphUser().get(requestConfiguration -> {
requestConfiguration.queryParameters.count = true;
requestConfiguration.queryParameters.orderby = new String []{"displayName"};
requestConfiguration.queryParameters.search = "\"displayName:Pr\"";
requestConfiguration.queryParameters.select = new String []{"displayName", "id"};
requestConfiguration.headers.add("ConsistencyLevel", "eventual");
});
const options = {
authProvider,
};
const client = Client.init(options);
let user = await client.api('/groups/{id}/members/microsoft.graph.user')
.version('beta')
.header('ConsistencyLevel','eventual')
.search('displayName:Pr')
.select('displayName,id')
.orderby('displayName')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Groups\Item\Members\Graph\User\UserRequestBuilderGetRequestConfiguration;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestConfiguration = new GraphUserRequestBuilderGetRequestConfiguration();
$headers = [
'ConsistencyLevel' => 'eventual',
];
$requestConfiguration->headers = $headers;
$queryParameters = GraphUserRequestBuilderGetRequestConfiguration::createQueryParameters();
$queryParameters->count = true;
$queryParameters->orderby = ["displayName"];
$queryParameters->search = "\"displayName:Pr\"";
$queryParameters->select = ["displayName","id"];
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->groups()->byGroupId('group-id')->members()->graphUser()->get($requestConfiguration)->wait();
Import-Module Microsoft.Graph.Beta.Groups
Get-MgBetaGroupMemberAsUser -GroupId $groupId -CountVariable CountVar -Sort "displayName" -Search '"displayName:Pr"' -Property "displayName,id" -ConsistencyLevel eventual
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.groups.item.members.graph.user.user_request_builder import UserRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
query_params = UserRequestBuilder.UserRequestBuilderGetQueryParameters(
count = True,
orderby = ["displayName"],
search = "\"displayName:Pr\"",
select = ["displayName","id"],
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
request_configuration.headers.add("ConsistencyLevel", "eventual")
result = await graph_client.groups.by_group_id('group-id').members.graph_user.get(request_configuration = request_configuration)
响应
以下示例显示了相应的响应。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/beta/$metadata#users(displayName,id)",
"@odata.count":7,
"value":[
{
"displayName":"Joseph Price",
"id":"11111111-2222-3333-4444-555555555555"
},
{
"displayName":"Preston Morales",
"id":"11111111-2222-3333-4444-555555555555"
}
]
}
示例 5:使用 $filter 来获取显示名称以字母 “A” 开头(包括返回的对象数目)的组会员资格
请求
以下示例显示了一个请求。
GET https://graph.microsoft.com/beta/groups/{id}/members?$count=true&$filter=startswith(displayName, 'a')
ConsistencyLevel: eventual
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].Members.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Count = true;
requestConfiguration.QueryParameters.Filter = "startswith(displayName, 'a')";
requestConfiguration.Headers.Add("ConsistencyLevel", "eventual");
});
mgc-beta groups members list --group-id {group-id} --filter "startswith(displayName, 'a')" --count "true" --consistency-level "eventual"
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
abstractions "github.com/microsoft/kiota-abstractions-go"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphgroups "github.com/microsoftgraph/msgraph-beta-sdk-go/groups"
//other-imports
)
headers := abstractions.NewRequestHeaders()
headers.Add("ConsistencyLevel", "eventual")
requestCount := true
requestFilter := "startswith(displayName, 'a')"
requestParameters := &graphgroups.ItemMembersRequestBuilderGetQueryParameters{
Count: &requestCount,
Filter: &requestFilter,
}
configuration := &graphgroups.ItemMembersRequestBuilderGetRequestConfiguration{
Headers: headers,
QueryParameters: requestParameters,
}
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
members, err := graphClient.Groups().ByGroupId("group-id").Members().Get(context.Background(), configuration)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
DirectoryObjectCollectionResponse result = graphClient.groups().byGroupId("{group-id}").members().get(requestConfiguration -> {
requestConfiguration.queryParameters.count = true;
requestConfiguration.queryParameters.filter = "startswith(displayName, 'a')";
requestConfiguration.headers.add("ConsistencyLevel", "eventual");
});
const options = {
authProvider,
};
const client = Client.init(options);
let members = await client.api('/groups/{id}/members')
.version('beta')
.header('ConsistencyLevel','eventual')
.filter('startswith(displayName, \'a\')')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Groups\Item\Members\MembersRequestBuilderGetRequestConfiguration;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestConfiguration = new MembersRequestBuilderGetRequestConfiguration();
$headers = [
'ConsistencyLevel' => 'eventual',
];
$requestConfiguration->headers = $headers;
$queryParameters = MembersRequestBuilderGetRequestConfiguration::createQueryParameters();
$queryParameters->count = true;
$queryParameters->filter = "startswith(displayName, 'a')";
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->groups()->byGroupId('group-id')->members()->get($requestConfiguration)->wait();
Import-Module Microsoft.Graph.Beta.Groups
Get-MgBetaGroupMember -GroupId $groupId -CountVariable CountVar -Filter "startswith(displayName, 'a')" -ConsistencyLevel eventual
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.groups.item.members.members_request_builder import MembersRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
query_params = MembersRequestBuilder.MembersRequestBuilderGetQueryParameters(
count = True,
filter = "startswith(displayName, 'a')",
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
request_configuration.headers.add("ConsistencyLevel", "eventual")
result = await graph_client.groups.by_group_id('group-id').members.get(request_configuration = request_configuration)
响应
以下示例显示了相应的响应。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/beta/$metadata#groups",
"@odata.count":76,
"value":[
{
"displayName":"AAD Contoso Users",
"mail":"AADContoso_Users@contoso.com",
"mailEnabled":true,
"mailNickname":"AADContoso_Users",
"securityEnabled":true
}
]
}
示例 6:使用 OData 强制转换检索添加为组成员的服务主体
请求
以下示例显示了一个请求。
GET https://graph.microsoft.com/beta/groups/3802e9bb-0951-4e18-b9eb-f934b4241194/members/microsoft.graph.servicePrincipal
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Groups["{group-id}"].Members.GraphServicePrincipal.GetAsync();
mgc-beta groups members graph-service-principal get --group-id {group-id}
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
//other-imports
)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphServicePrincipal, err := graphClient.Groups().ByGroupId("group-id").Members().GraphServicePrincipal().Get(context.Background(), nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
ServicePrincipalCollectionResponse result = graphClient.groups().byGroupId("{group-id}").members().graphServicePrincipal().get();
const options = {
authProvider,
};
const client = Client.init(options);
let servicePrincipal = await client.api('/groups/3802e9bb-0951-4e18-b9eb-f934b4241194/members/microsoft.graph.servicePrincipal')
.version('beta')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->groups()->byGroupId('group-id')->members()->graphServicePrincipal()->get()->wait();
Import-Module Microsoft.Graph.Beta.Groups
Get-MgBetaGroupMemberAsServicePrincipal -GroupId $groupId
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
result = await graph_client.groups.by_group_id('group-id').members.graph_service_principal.get()
响应
以下示例显示了相应的响应。
注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#servicePrincipals",
"value": [
{
"id": "11111111-2222-3333-4444-555555555555",
"deletedDateTime": null,
"accountEnabled": true,
"appDisplayName": "Contoso Azure App",
"appId": "11111111-2222-3333-4444-555555555555",
}
]
}