Directory API 提供了用于创建、更新和删除用户的程序化方法。您还可以获取有关符合指定条件的单个用户或用户列表的信息。以下是一些基本用户操作的示例。
创建用户账号
您可以将用户账号添加到 Google Workspace 账号的任何网域中。在添加用户账号之前,请确认域名所有权。
如果您已将个人 Gmail 账号升级为使用自有域名的企业电子邮件账号,则必须先解锁其他 Google Workspace 设置,然后才能创建新的用户账号。如需了解详情,请参阅G Suite 企业电子邮件账号已更新为 G Suite 基本版账号。
如需使用您的某个网域创建用户账号,请使用以下 POST 请求,并包含了解身份验证和授权中所述的授权。您可以在 OAuth 2.0 范围列表中查看 Directory API 的可用范围。如需了解请求查询字符串属性,请参阅 users.insert() 方法。
POST https://admin.googleapis.com/admin/directory/v1/users
所有创建请求都需要您提交满足请求所需的信息。如果您使用的是客户端库,它们会将您所选语言的数据对象转换为格式化的 JSON 数据对象。
JSON 请求
以下 JSON 展示了用于创建用户的示例请求。如需查看请求和响应属性的完整列表,请参阅 API 参考文档。
{ "primaryEmail": "liz@example.com", "name": { "givenName": "Elizabeth", "familyName": "Smith" }, "suspended": false, "password": "new user password", "hashFunction": "SHA-1", "changePasswordAtNextLogin": false, "ipWhitelisted": false, "ims": [ { "type": "work", "protocol": "gtalk", "im": "liz_im@talk.example.com", "primary": true } ], "emails": [ { "address": "liz@example.com", "type": "home", "customType": "", "primary": true } ], "addresses": [ { "type": "work", "customType": "", "streetAddress": "1600 Amphitheatre Parkway", "locality": "Mountain View", "region": "CA", "postalCode": "94043" } ], "externalIds": [ { "value": "12345", "type": "custom", "customType": "employee" } ], "organizations": [ { "name": "Google Inc.", "title": "SWE", "primary": true, "type": "work", "description": "Software engineer" } ], "phones": [ { "value": "+1 nnn nnn nnnn", "type": "work" } ], "orgUnitPath": "/corp/engineering", "includeInGlobalAddressList": true }
如果创建请求的查询速率过高,您可能会收到 API 服务器发出的 HTTP 503 响应,表明您已超出配额。如果您收到这些响应,请使用指数退避算法重试请求。
关于新账号,请注意以下事项:
- 如果 Google 账号已购买邮件许可,系统会自动为新用户账号分配邮箱。此分配可能需要几分钟才能完成并激活。
- 在请求中修改只读字段(例如
isAdmin)会被 API 服务默默忽略。 - 一个账号中允许的域名数量上限为 600 个(1 个主域名 + 599 个附加域名)
- 如果用户账号在创建时未分配给特定组织部门,则该账号位于顶级组织部门中。用户所属的组织部门决定了用户可以访问哪些 Google Workspace 服务。如果用户被移至新组织,其访问权限会发生变化。如需详细了解组织结构,请参阅管理帮助中心。如需详细了解如何将用户移至其他组织,请参阅更新用户。
- 新用户账号必须提供
password。如果指定了hashFunction,则密码必须是有效的哈希键。如果未指定,密码应为明文,长度介于 8 到 100 个 ASCII 字符之间。如需了解详情,请参阅 API 参考文档。 - 对于采用 Google Workspace 弹性方案的用户,使用此 API 创建用户会产生费用,并会导致客户结算账号产生相应费用。如需了解详情,请参阅 API 结算信息。
- Google Workspace 账号可以包含您的任何网域。在多网域账号中,一个网域中的用户可以与其他账号网域中的用户共享服务。如需详细了解多个网域中的用户,请参阅 API 多网域信息。
- 可能存在有冲突的账号。检查您计划添加的用户是否已拥有 Google 账号。然后按照相关步骤操作,以避免与这些账号冲突。请参阅查找和处理有冲突的账号。
- 可能存在访问者账号。如果用户邀请贵组织以外没有 Google 账号的人员在 Google 云端硬盘中协作,受邀人员将获得访客账号,账号格式为 visitor's_username@your_domain.com。如果您添加的用户与访客账号的用户名相同,则该账号将转换为完整的 Google Workspace 账号。该账号将保留其现有的云端硬盘文件权限。请参阅与访客共享文档。
成功的响应会返回 HTTP 200 状态代码。除了状态代码以外,响应还会返回新用户账号的属性。
更新用户账号
如需更新用户账号,请使用以下 PUT 请求,并在其中添加授权请求中所述的授权。userKey 可以是用户的主电子邮件地址、唯一用户 id 或用户的某个别名电子邮件地址。
PUT https://admin.googleapis.com/admin/directory/v1/users/userKey
请求正文和响应正文均包含一个 User 实例。不过,Directory API 支持 patch 语义,因此您只需在请求中提交更新后的字段。
示例请求
在以下示例中,用户账号创建时,用户的 givenName 为“Elizabeth”,并且仅提供了工作电子邮件地址。
{
"name": {
"givenName": "Elizabeth",
"familyName": "Smith"
},
"emails": [
{
"address": "liz@example.com",
"type": "work",
"primary": true
}
]
}
以下请求将 givenName 从“Elizabeth”更新为“Liz”,并添加了一个家庭电子邮件地址。请注意,由于该字段是一个数组,因此两个电子邮件地址都完整提供。
PUT https://admin.googleapis.com/admin/directory/v1/users/liz@example.com
{
"name": {
"givenName": "Liz",
},
"emails": [
{
"address": "liz@example.com",
"type": "work",
"primary": true
},
{
"address": "liz@home.com",
"type": "home"
}
]
}
成功的响应会返回 HTTP 200 状态代码和包含更新后字段的 User 资源。
更新用户的账号名称时,请注意以下事项:
- 重命名用户账号会更改用户的主电子邮件地址以及检索该用户的信息时使用的网域。在重命名用户之前,我们建议您让用户退出所有浏览器会话和服务。
- 重命名用户账号的过程可能需要长达 10 分钟才能在所有服务中生效。
- 重命名用户后,旧用户名会保留为别名,以确保在设置了电子邮件转发的情况下,用户能继续收发邮件,但不能用作新用户名。
- 一般来说,我们还建议不要使用用户电子邮件地址作为持久性数据的键,因为电子邮件地址可能会发生变化。
- 如需查看在 Google Workspace 应用中重命名用户所产生的全部影响,请参阅管理员帮助中心。
将用户设为管理员
如需将用户设为超级管理员,请使用以下 POST 请求,并在其中添加授权请求中所述的授权。userKey 可以是用户的主电子邮件地址、唯一用户 id 或用户的某个别名电子邮件地址。如需了解请求和响应属性,请参阅 API 参考文档。如需详细了解超级管理员,请参阅管理帮助中心。
POST https://admin.googleapis.com/admin/directory/v1/users/userKey/makeAdminJSON 请求
在此示例中,userKey 为 liz@example.com 的用户已成为超级用户:
POST https://admin.googleapis.com/admin/directory/v1/users/liz@example.com/makeAdmin
{
"status": true
}成功的响应会返回 HTTP 200 状态代码。
管理用户关系
Directory API 使用 relations 字段来定义用户之间的不同类型的关系。在商业环境中,人们通常使用此字段来表示经理与员工和助理之间的关系,但此字段也支持许多其他类型的关系。关系会显示在任何支持该卡片的 Google Workspace 应用中用户的“相关人员”卡片中。如需查看个人资料卡片的显示位置示例,请参阅向用户目录中的个人资料添加信息。
创建用户之间的关系
您只能定义一个方向的关系,从包含 relations 字段的“所有者”用户记录开始。type 用于描述其他人员与所有权用户之间的关系。例如,在经理-员工关系中,员工是所有者用户,您需要向其账号添加 manager 类型的 relations 字段。如需了解允许的类型,请参阅 User 对象参考。
通过以下方式设置关系:创建或更新包含 relations 字段的 JSON 请求正文,以设置所有者用户。
您可以在一个请求中创建多个关系。
{
"relations": [
{
"value": "EMAIL_ADDRESS_RELATION_1",
"type": "manager"
},
{
"value": "EMAIL_ADDRESS_RELATION_2",
"type": "dotted_line_manager"
}
]
}
更新或删除关系
您只能整体更新 relations 字段,而无法针对列出的个人单独更新该字段,以更改关系类型或移除相应人员。在上述示例中,如需移除现有的经理账号关系,并将虚线经理账号设为所有权用户的经理账号,请使用您现在希望的所有字段值更新所有权用户的账号。
{
"relations": [
{
"value": "EMAIL_ADDRESS_RELATION_2",
"type": "manager"
}
]
}
如需移除所有拥有用户的关系,请将 relations 设置为空:
{
"relations": []
}
检索用户
如需检索用户,请使用以下 GET 请求,并包含授权请求中所述的授权。userKey 可以是用户的主电子邮件地址、唯一用户 id 或用户的某个别名电子邮件地址。如需了解请求和响应属性,请参阅 API 参考文档。
GET https://admin.googleapis.com/admin/directory/v1/users/userKey此示例返回了主电子邮件地址或别名电子邮件地址为 liz@example.com 的用户的用户账号属性:
GET https://admin.googleapis.com/admin/directory/v1/users/liz@example.com
JSON 响应
成功的响应会返回 HTTP 200 状态代码。除了状态代码以外,响应还会返回用户账号的属性。
{ "kind": "directory#user", "id": "the unique user id", "primaryEmail": "liz@example.com", "name": { "givenName": "Liz", "familyName": "Smith", "fullName": "Liz Smith" }, "isAdmin": true, "isDelegatedAdmin": false, "lastLoginTime": "2013-02-05T10:30:03.325Z", "creationTime": "2010-04-05T17:30:04.325Z", "agreedToTerms": true, "hashFunction": "SHA-1", "suspended": false, "changePasswordAtNextLogin": false, "ipWhitelisted": false, "ims": [ { "type": "work", "protocol": "gtalk", "im": "lizim@talk.example.com", "primary": true } ], "emails": [ { "address": "liz@example.com", "type": "home", "customType": "", "primary": true } ], "addresses": [ { "type": "work", "customType": "", "streetAddress": "1600 Amphitheatre Parkway", "locality": "Mountain View", "region": "CA", "postalCode": "94043" } ], "externalIds": [ { "value": "employee number", "type": "custom", "customType": "office" } ], "organizations": [ { "name": "Google Inc.", "title": "SWE", "primary": true, "customType": "", "description": "Software engineer" } ], "phones": [ { "value": "+1 nnn nnn nnnn", "type": "work" } ], "aliases": [ "lizsmith@example.com", "lsmith@example.com" ], "nonEditableAliases": [ "liz@test.com" ], "customerId": "C03az79cb", "orgUnitPath": "corp/engineering", "isMailboxSetup": true, "includeInGlobalAddressList": true }
检索网域中的所有用户
如需检索同一网域中的所有用户,请使用以下 GET 请求,并包含授权请求中所述的授权。为了方便阅读,此示例使用回车断行:
GET https://admin.googleapis.com/admin/directory/v1/users ?domain=primary domain name&pageToken=token for next results page &maxResults=max number of results per page &orderBy=email, givenName, or familyName &sortOrder=ascending or descending &query=email, givenName, or familyName:the query's value*
如需了解请求和响应属性,请参阅 API 参考文档。
JSON 响应
在此示例中,系统会返回 example.com 网域中的所有用户,每个响应页面最多包含 2 个用户网域。此响应中后续的用户列表的 nextPageToken。默认情况下,系统会返回一个包含 100 位用户的列表,并按用户电子邮件地址的字母顺序排序:
GET https://admin.googleapis.com/admin/directory/v1/users?domain=example.com&maxResults=2
成功的响应会返回 HTTP 200 状态代码。除了状态代码之外,响应还会返回 example.com 网域中的 2 个用户账号 (maxResults=2):
{ "kind": "directory#users", "users": [ { "kind": "directory#user", "id": "the unique user id", "primaryEmail": "liz@example.com", "name": { "givenName": "Liz", "familyName": "Smith", "fullName": "Liz Smith" }, "isAdmin": true, "isDelegatedAdmin": false, "lastLoginTime": "2013-02-05T10:30:03.325Z", "creationTime": "2010-04-05T17:30:04.325Z", "agreedToTerms": true, "hashFunction": "SHA-1", "suspended": false, "changePasswordAtNextLogin": false, "ipWhitelisted": false, "ims": [ { "type": "work", "protocol": "gtalk", "im": "lizim@talk.example.com", "primary": true } ], "emails": [ { "address": "liz@example.com", "type": "work", "customType": "", "primary": true } ], "addresses": [ { "type": "work", "customType": "", "streetAddress": "1600 Amphitheatre Parkway", "locality": "Mountain View", "region": "CA", "postalCode": "94043" } ], "externalIds": [ { "value": "employee number", "type": "custom", "customType": "office" } ], "organizations": [ { "name": "Google Inc.", "title": "SWE", "primary": true, "customType": "", "description": "Software engineer" } ], "phones": [ { "value": "+1 nnn nnn nnnn", "type": "work" } ], "aliases": [ "lizsmith@example.com", "lsmith@example.com" ], "nonEditableAliases": [ "liz@test.com" ], "customerId": "C03az79cb", "orgUnitPath": "corp/engineering", "isMailboxSetup": true, "includeInGlobalAddressList": true }, { "kind": "directory#user", "id": "user unique ID", "primaryEmail": "admin2@example.com", "name": { "givenName": "admin", "familyName": "two", "fullName": "admin two" }, "isAdmin": true, "isDelegatedAdmin": true, "lastLoginTime": "2013-02-05T10:30:03.325Z", "creationTime": "2010-04-05T17:30:04.325Z", "agreedToTerms": true, "hashFunction": "SHA-1", "suspended": true, "suspensionReason": "ADMIN", "changePasswordAtNextLogin": false, "ipWhitelisted": false, "emails": [ { "address": "admin2@example.com", "type": "work", "customType": "", "primary": true } ], "externalIds": [ { "value": "contractor license number", "type": "custom", "customType": "work" } ], "aliases": [ "second_admin@example.com" ], "nonEditableAliases": [ "admin@test.com" ], "customerId": "C03az79cb", "orgUnitPath": "corp/engineering", "isMailboxSetup": true, "includeInGlobalAddressList": true } ], "nextPageToken": "next page token" }
检索所有账号用户
如需检索账号中的所有用户(账号可以包含多个网域),请使用以下 GET 请求,并在其中添加授权请求中所述的授权。为了方便阅读,此示例使用回车断行:
GET https://admin.googleapis.com/admin/directory/v1/users ?customer=my_customer or customerId&pageToken=token for next results page &maxResults=max number of results per page &orderBy=email, givenName, or familyName &sortOrder=ascending or descending &query=user attributes
customer查询字符串是my_customer或customerId值。- 使用字符串
my_customer表示账号的customerId。 - 作为转销客户的管理员,请使用转销客户的
customerId。对于customerId,请在检索网域中的所有用户操作的请求中使用账号的主域名。生成的响应具有customerId值。 - 可选的
orderBy查询字符串用于确定列表是按用户的主电子邮件地址、姓氏还是名字排序。使用orderBy时,您还可以使用sortOrder查询字符串按升序或降序列出结果。 - 可选的
query查询字符串允许在用户个人资料中的多个字段(包括核心字段和自定义字段)中进行搜索。如需查看示例,请参阅搜索用户。
如需了解请求和响应属性,请参阅 API 参考文档。
在此示例中,账号管理员请求返回账号中的所有用户,并在每个响应页面上显示一个用户条目。nextPageToken 会转到后续结果页面:
GET https://admin.googleapis.com/admin/directory/v1/users?customer=my_customer&maxResults=1
在此示例中,转销商管理员正在请求转销账号中的所有用户,该账号的 customerId 值为 C03az79cb。
GET https://admin.googleapis.com/admin/directory/v1/users?customer=C03az79cb&maxResults=1
JSON 响应
成功的响应会返回 HTTP 200 状态代码。除了状态代码以外,响应还会返回相应账号中的所有用户:
{ "kind": "directory#users", "users": [ { "kind": "directory#user", "id": "the unique user id", "username": "admin2@example.com", "name": { "givenName": "admin", "familyName": "two", "fullName": "admin two" }, "isAdmin": true, "isDelegatedAdmin": true, "lastLoginTime": "2013-02-05T10:30:03.325Z", "creationTime": "2010-04-05T17:30:04.325Z", "agreedToTerms": true, "hashFunction": "SHA-1", "suspended": false, "changePasswordAtNextLogin": false, "ipWhitelisted": false, "emails": [ { "address": "admin2@example.com", "type": "work", "customType": "", "primary": true } ], "externalIds": [ { "value": "employee number", "type": "custom", "customType": "office" } ], "aliases": [ "second_admin@example.com" ], "nonEditableAliases": [ "another_admin@test.com" ], "customerId": "C03az79cb", "orgUnitPath": "/", "isMailboxSetup": true, "includeInGlobalAddressList": true }, { "kind": "directory#user", "id": "the unique user id", "username": "liz@example.com", "name": { "givenName": "Elizabeth", "familyName": "Smith", "fullName": "Elizabeth Smith" }, "isAdmin": false, "isDelegatedAdmin": false, "lastLoginTime": "1336509883546", "creationTime": "1404802800000", "agreedToTerms": false, "hashFunction": "SHA-1", "suspended": false, "changePasswordAtNextLogin": false, "ipWhitelisted": false, "emails": [ { "address": "liz@example.com", "type": "home", "customType": "", "primary": true } ], "externalIds": [ { "value": "employee number", "type": "custom", "customType": "bank" } ], "relations": [ { "value": "liz", "type": "friend", "customType": "" } ], "aliases": [ "lizsmith@example.com", "lsmith@example.com" ], "nonEditableAliases": [ "liz@test.com" ], "customerId": "C03az79cb", "orgUnitPath": "/", "isMailboxSetup": true, "includeInGlobalAddressList": true }, { "kind": "directory#user", "id": "the unique user id", "username": "test3@example.com", "name": { "givenName": "Tester", "familyName": "Three", "fullName": "Tester Three" }, "isAdmin": false, "isDelegatedAdmin": false, "lastLoginTime": "1336509883546", "creationTime": "1404802800000", "agreedToTerms": true, "hashFunction": "SHA-1", "suspended": false, "changePasswordAtNextLogin": false, "ipWhitelisted": false, "emails": [ { "address": "test@example.com", "type": "work", "customType": "", "primary": true } ], "externalIds": [ { "value": "employee number", "type": "custom", "customType": "office" } ], "aliases": [ "tester3@example.com" ], "nonEditableAliases": [ "third@test.com" ], "customerId": "C03az79cb", "orgUnitPath": "/", "isMailboxSetup": true, "includeInGlobalAddressList": true }, { "kind": "directory#user", "id": "the unique user id", "username": "work_admin@example.com", "name": { "givenName": "Admin", "familyName": "Work", "fullName": "Admin Work" }, "isAdmin": true, "isDelegatedAdmin": true, "lastLoginTime": "1336509883546", "creationTime": "1404802800000", "agreedToTerms": true, "hashFunction": "SHA-1", "suspended": false, "changePasswordAtNextLogin": false, "ipWhitelisted": false, "emails": [ { "address": "work_admin@example.com", "type": "work", "customType": "", "primary": true } ], "externalIds": [ { "value": "employee number", "type": "custom", "customType": "office" } ], "aliases": [ "my_alias@example.com" ], "nonEditableAliases": [ "other_alias@test.com" ], "customerId": "C03az79cb", "orgUnitPath": "/", "isMailboxSetup": true, "includeInGlobalAddressList": true } ], "nextPageToken": "NNNNN" }
检索最近删除的用户
如需检索账号或账号的某个网域在过去 20 天内删除的所有用户,请使用以下 GET 请求,并包含授权请求中所述的授权。如需恢复删除的用户,请参阅恢复删除的用户。
如需从账号的主网域或子网域中检索过去 20 天内删除的用户,请使用以下 GET 请求。domain 查询字符串是网域的主域名。如需了解用户请求和响应属性,请参阅 API 参考文档。为了方便阅读,此示例使用回车断行:
GET https://admin.googleapis.com/admin/directory/v1/users ?domain=primary domain name&pageToken=token for next results page &maxResults=max number of results per page &showDeleted=true
GET 请求。为了方便阅读,此示例使用回车断行:
GET https://admin.googleapis.com/admin/directory/v1/users ?customer=my_customer or customerId&pageToken=token for next results page &maxResults=max number of results per page&showDeleted=true
customer查询字符串是my_customer或customerId值。- 作为账号管理员,您可以使用字符串
my_customer来表示您账号的customerId。 - 作为转销客户的管理员,请使用转销客户的
customerId。对于customerId,请在检索网域中的所有用户操作的请求中使用账号的主域名。生成的响应具有customerId值。
如需了解请求和响应属性,请参阅 API 参考文档。
在此示例中,账号管理员请求获取账号中所有已删除的用户:
GET https://admin.googleapis.com/admin/directory/v1/users?customer=my_customer&showDeleted=true
JSON 响应
成功的响应会返回 HTTP 200 状态代码。除了状态代码之外,响应还会返回过去 20 天内删除的所有账号用户:
{ "kind": "directory#users", "users": [ { "kind": "directory#user", "id": "the unique user id", "primaryEmail": "user1@example.com" }, { "kind": "directory#user", "id": "the unique user id", "primaryEmail": "user3@example.com" } ], "nextPageToken": "token for next page of deleted users" }
检索用户的照片
该 API 会检索一张照片缩略图,即最新的 Google 个人资料照片。如需检索用户的最新照片,请使用以下 GET 请求,并包含为请求授权中所述的授权。userKey 可以是用户的主电子邮件地址、用户 id 或用户的任何别名电子邮件地址。如需了解请求和响应属性,请参阅 API 参考文档。
GET https://admin.googleapis.com/admin/directory/v1/users/userKey/photos/thumbnail在此示例中,系统会返回 liz@example.com 的最新照片:
GET https://admin.googleapis.com/admin/directory/v1/users/liz@example.com/photos/thumbnail
JSON 响应
成功的响应会返回 HTTP 200 状态代码。
{ "kind": "directory#user#photo", "id": "the unique user id", "primaryEmail": "liz@example.com", "mimeType": "the photo mime type", "height": "the photo height in pixels", "width": "the photo width in pixels", "photoData": "web safe base64 encoded photo data" }
API 对照片进行的网络安全 base64 编码与 RFC 4648 'base64url' 类似。这意味着:
- 斜杠 (/) 字符会被替换为下划线 (_) 字符。
- 加号 (+) 字符替换为连字符 (-) 字符。
- 等号 (=) 字符替换为星号 (*)。
- 对于填充,我们使用句点 (.) 字符,而不是 RFC-4648 base网址 定义中用于填充的等号 (=)。这样做的目的是简化网址解析。
- 无论上传的照片大小如何,该 API 都会按比例将其缩小为 96x96 像素。
如果您需要通过 JavaScript 创建兼容的链接,Google Closure 库包含 Base64 编码和解码函数,这些函数已根据 Apache 许可发布。
以非管理员身份检索用户
虽然用户账号只能由管理员修改,但网域中的任何用户都可以读取用户个人资料。非管理员用户可以发出 users.get 或 users.list 请求,并将 viewType 参数设置为 domain_public,以检索用户的公开个人资料。范围 https://www.googleapis.com/auth/admin.directory.user.readonly 非常适合此使用情形。
domain_public 视图允许非管理员用户访问一组标准的核心字段。对于自定义字段,您可以在定义架构时选择将其设为公开或不公开。
更新用户的照片
如需更新用户的照片,请使用以下 PUT 请求,并在其中添加“授权请求”中所述的授权令牌。userKey 可以是用户的主电子邮件地址、用户 id 或任何用户别名的电子邮件地址。如需了解请求和响应属性,请参阅 API 参考文档。
PUT https://admin.googleapis.com/admin/directory/v1/users/userKey/photos/thumbnail在此示例中,系统会更新 liz@example.com 的照片:
PUT https://admin.googleapis.com/admin/directory/v1/users/liz@example.com/photos/thumbnail
{
"photoData": "web safe base64 encoded photo data"
}更新照片时,API 会忽略 height 和 width。
JSON 响应
成功的响应会返回 HTTP 200 状态代码。
{ "kind": "directory#user#photo", "id": "the unique user id", "primaryEmail": "liz@example.com", "mimeType": "the photo mime type", "height": "the photo height in pixels", "width": "the photo width in pixels", "photoData": "web safe base64 encoded photo data" }
删除用户的照片
如需删除用户的照片,请使用以下 DELETE 请求,并包含“授权请求”中所述的授权。userKey 可以是用户的主电子邮件地址、用户 id 或任何用户别名的电子邮件地址。如需了解请求和响应属性,请参阅 API 参考文档。
DELETE https://admin.googleapis.com/admin/directory/v1/users/userKey/photos/thumbnail删除后,系统不会显示用户的照片。在需要显示用户照片的任何位置,系统都会改为显示轮廓。
删除用户账号
如需删除用户账号,请使用以下 DELETE 请求,并在其中添加授权请求中所述的授权令牌。userKey 可以是用户的主电子邮件地址、唯一用户 id 或用户的某个别名电子邮件地址。如需了解请求和响应属性,请参阅 API 参考文档。
DELETE https://admin.googleapis.com/admin/directory/v1/users/userKey在此示例中,系统会删除 liz@example.com 用户账号:
DELETE https://admin.googleapis.com/admin/directory/v1/users/liz@example.com
成功的响应只会返回 HTTP 200 状态代码。
删除用户之前需要考虑的重要事项:
- 被删除的用户将无法再登录。
- 如需详细了解用户账号删除,请参阅管理帮助中心。
恢复已删除的用户账号
在过去 20 天内删除的用户必须满足某些条件,然后才能恢复相应用户的账号。
如需取消删除用户账号,请使用以下 POST 请求,并在其中添加为请求授权中所述的授权。userKey 是在检索过去 20 天内删除的用户操作的响应中找到的唯一身份用户 id。用户的电子邮件主地址或别名电子邮件地址不能用于此操作的 userKey 中。如需了解请求和响应属性,请参阅 API 参考文档。
POST https://admin.googleapis.com/admin/directory/v1/users/userKey/undelete在此示例中,用户 liz@example.com 已取消删除。系统会恢复此用户之前的所有账号属性:
POST https://admin.googleapis.com/admin/directory/v1/users/12309329403209438205/undelete
成功的响应只会返回 HTTP 204 状态代码。如需查看已恢复的用户账号,请使用检索用户操作。