【发布时间】:2016-12-05 15:12:58
【问题描述】:
如何使用 Google API 获取我们公司域下的所有用户 ID?
我想获取我们域下所有用户的列表。
然后我想获取每个用户的所有电子邮件列表。
【问题讨论】:
标签: google-api gmail-api google-admin-sdk
如何使用 Google API 获取我们公司域下的所有用户 ID?
我想获取我们域下所有用户的列表。
然后我想获取每个用户的所有电子邮件列表。
【问题讨论】:
标签: google-api gmail-api google-admin-sdk
我想你指的是Retrieve all users in a domain:
要检索同一域中的所有用户,请使用以下
GET请求并包含Authorize requests 中描述的授权。为便于阅读,此示例使用换行符:
GET https://www.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*
默认情况下,系统会返回一个包含 100 个用户的列表,按照用户邮箱地址的字母顺序排列:
GET https://www.googleapis.com/admin/directory/v1/users?domain=example.com&maxResults=2
成功的响应返回HTTP 200 status code。除了状态码,响应还返回 example.com 域 (maxResults=2) 中的 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"
}
],
"relations": [
{
"value": "susan",
"type": "friend",
"customType": ""
}
],
"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"
}
],
"relations": [
{
"value": "liz",
"type": "friend",
"customType": ""
}
],
"aliases": [
"second_admin@example.com"
],
"nonEditableAliases: [
"admin@test.com"
],
"customerId": "C03az79cb",
"orgUnitPath": "corp/engineering",
"isMailboxSetup": true,
"includeInGlobalAddressList": true
}
],
"nextPageToken": "next page token"
}
您也可以查看Retrieve all account users
要检索可以包含多个域的帐户中的所有用户,请使用以下
GET请求并包含Authorize requests 中描述的授权。
【讨论】: