Groups Service
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
群组
此服务允许脚本访问 Google 群组。它可用于查询群组的电子邮件地址或用户是直接成员的群组列表等信息。以下示例展示了当前用户是多少个群组的成员:
var groups = GroupsApp.getGroups();
Logger.log('You are a member of %s Google Groups.', groups.length);
类
名称 | 简介 |
Group | 一个群组对象,您可以查询其成员以及这些成员在群组中的角色。 |
GroupsApp | 此类提供对 Google 群组信息的访问权限。 |
Role | 用户在群组中的可能角色,例如所有者或普通成员。 |
属性
属性 | 类型 | 说明 |
OWNER | Enum | 群组的所有者。 |
MANAGER | Enum | 群组的管理员。 |
MEMBER | Enum | 此群组的成员,但既不是所有者也不是管理员。 |
INVITED | Enum | 群组所有者或管理员邀请加入群组,但尚未接受邀请的用户。 |
PENDING | Enum | 已请求加入群组,但尚未获得所有者或管理员批准的用户。 |
BANNED | Enum | 被禁止加入某个群组的用户,无法尝试加入该群组。 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eThe Groups service enables scripts to interact with Google Groups, allowing tasks like retrieving group details and user memberships.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGroup\u003c/code\u003e class represents a Google Group, providing methods to access its email, members, roles, and child groups.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGroupsApp\u003c/code\u003e class provides methods for retrieving group information, such as finding a group by email or listing a user's memberships.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eRole\u003c/code\u003e enum defines the possible roles a user can have within a group (e.g., OWNER, MEMBER).\u003c/p\u003e\n"]]],[],null,["# Groups Service\n\nGroups\n\nThis service allows scripts to access Google Groups. It can be used to query\ninformation such as a group's email address, or the list of groups in which the\nuser is a direct member. Here's an example that shows how many groups the\ncurrent user is a member of: \n\n var groups = GroupsApp.getGroups();\n Logger.log('You are a member of %s Google Groups.', groups.length);\n\nClasses\n-------\n\n| Name | Brief description |\n|-------------------------------------------------------|----------------------------------------------------------------------------------------|\n| [Group](/apps-script/reference/groups/group) | A group object whose members and those members' roles within the group can be queried. |\n| [GroupsApp](/apps-script/reference/groups/groups-app) | This class provides access to Google Groups information. |\n| [Role](/apps-script/reference/groups/role) | Possible roles of a user within a group, such as owner or ordinary member. |\n\n[Group](/apps-script/reference/groups/group)\n--------------------------------------------\n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------------------------------|------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| [getEmail()](/apps-script/reference/groups/group#getEmail()) | `String` | Gets this group's email address. |\n| [getGroups()](/apps-script/reference/groups/group#getGroups()) | [Group[]](/apps-script/reference/groups/group) | Retrieves the direct child groups of the group. |\n| [getRole(email)](/apps-script/reference/groups/group#getRole(String)) | [Role](/apps-script/reference/groups/role) | Retrieves a user's role in the context of the group. |\n| [getRole(user)](/apps-script/reference/groups/group#getRole(User)) | [Role](/apps-script/reference/groups/role) | Retrieves a user's role in the context of the group. |\n| [getRoles(users)](/apps-script/reference/groups/group#getRoles(User)) | [Role[]](/apps-script/reference/groups/role) | Retrieves users' roles in the context of the group. |\n| [getUsers()](/apps-script/reference/groups/group#getUsers()) | [User[]](../base/user.html) | Gets the direct members and banned members of the group that have a known corresponding Google account. |\n| [hasGroup(group)](/apps-script/reference/groups/group#hasGroup(Group)) | `Boolean` | Tests if a group is a direct member of this group. |\n| [hasGroup(email)](/apps-script/reference/groups/group#hasGroup(String)) | `Boolean` | Tests if a group is a direct member of this group. |\n| [hasUser(email)](/apps-script/reference/groups/group#hasUser(String)) | `Boolean` | Tests if a user is a direct member of the group. |\n| [hasUser(user)](/apps-script/reference/groups/group#hasUser(User)) | `Boolean` | Tests if a user is a direct member of the group. |\n\n[GroupsApp](/apps-script/reference/groups/groups-app)\n-----------------------------------------------------\n\n### Properties\n\n| Property | Type | Description |\n|----------|--------------------------------------------|-------------|\n| `Role` | [Role](/apps-script/reference/groups/role) | |\n\n### Methods\n\n| Method | Return type | Brief description |\n|--------------------------------------------------------------------------------------------|------------------------------------------------|----------------------------------------------------------------------------------|\n| [getGroupByEmail(email)](/apps-script/reference/groups/groups-app#getGroupByEmail(String)) | [Group](/apps-script/reference/groups/group) | Retrieves the group having the specified email address. |\n| [getGroups()](/apps-script/reference/groups/groups-app#getGroups()) | [Group[]](/apps-script/reference/groups/group) | Retrieves all the groups of which you are a direct member (or a pending member). |\n\n[Role](/apps-script/reference/groups/role)\n------------------------------------------\n\n### Properties\n\n| Property | Type | Description |\n|-----------|--------|------------------------------------------------------------------------------------------------------------------------------|\n| `OWNER` | `Enum` | The owner of a group. |\n| `MANAGER` | `Enum` | The manager of a group. |\n| `MEMBER` | `Enum` | A user who is a member of this group but is neither an owner nor a manager. |\n| `INVITED` | `Enum` | A user who has been invited to join a group by an owner or manager of the group but who has not yet accepted the invitation. |\n| `PENDING` | `Enum` | A user who has requested to join a group but who has not yet been approved by an owner or manager. |\n| `BANNED` | `Enum` | A user who has been banned from a group and cannot attempt to join it. |"]]