2016-07-31 29 views
1

如何使用Google API獲取我們公司域下的所有用戶ID?獲取域名下的所有用戶ID

我想獲取我們域下所有用戶的列表。

然後我想要得到每個用戶的所有電子郵件列表。

回答

1

我想你指的是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域中的2個用戶帳戶(maxResults=2):

{ 
"kind": "directory#users", 
"users": [ 
    { 
    "kind": "directory#user", 
    "id": "the unique user id", 
    "primaryEmail": "[email protected]", 
    "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": "[email protected]", 
    "primary": true 
    } 
    ], 
    "emails": [ 
    { 
    "address": "[email protected]", 
    "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": [ 
    "[email protected]", 
    "[email protected]" 
    ], 
    "nonEditableAliases: [ 
    "[email protected]" 
    ], 
    "customerId": "C03az79cb", 
    "orgUnitPath": "corp/engineering", 
    "isMailboxSetup": true, 
    "includeInGlobalAddressList": true 
    }, 
    { 
    "kind": "directory#user", 
    "id": "user unique ID", 
    "primaryEmail": "[email protected]", 
    "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": "[email protected]", 
    "type": "work", 
    "customType": "", 
    "primary": true 
    } 
    ], 
    "externalIds": [ 
    { 
    "value": "contractor license number", 
    "type": "custom", 
    "customType": "work" 
    } 
    ], 
    "relations": [ 
    { 
    "value": "liz", 
    "type": "friend", 
    "customType": "" 
    } 
    ], 
    "aliases": [ 
    "[email protected]" 
    ], 
    "nonEditableAliases: [ 
    "[email protected]" 
    ], 
    "customerId": "C03az79cb", 
    "orgUnitPath": "corp/engineering", 
    "isMailboxSetup": true, 
    "includeInGlobalAddressList": true 
    } 
], 
"nextPageToken": "next page token" 
} 

您還可以檢查出Retrieve all account users

檢索所有用戶帳戶它可以由多個域組成,請使用以下GET請求幷包含Authorize requests中描述的授權。

相關問題