Directory API 提供透過程式建立、更新及刪除使用者的程式輔助方法。此外,您還可以取得個別使用者的相關資訊,或是符合特定條件的使用者名單。以下列舉一些基本的使用者作業。
建立使用者帳戶
您可以在任何 Google Workspace 帳戶的網域中新增使用者帳戶。新增使用者帳戶之前,請確認網域擁有權。
如果您已將個人 Gmail 帳戶升級為使用自有網域名稱的企業電子郵件帳戶,則必須先解鎖其他 Google Workspace 設定,才能建立新的使用者帳戶。詳情請參閱將 G Suite 企業電子郵件帳戶更新為 G Suite Basic 帳戶。
如要使用您的其中一個網域建立使用者帳戶,請執行下列 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 帳戶已購買郵件授權,系統將自動為新的使用者帳戶指派信箱。這項作業可能需要幾分鐘才能完成及啟用。
- API 服務會忽略要求中的唯讀欄位 (例如
isAdmin
),而不會顯示相關通知。 - 每個帳戶允許的網域數量上限為 600 個 (1 個主網域 + 599 個其他網域)
- 如果在建立使用者帳戶時,並未將使用者指派至特定機構單位,則該帳戶會屬於頂層機構單位。使用者能存取的 Google Workspace 服務取決於使用者的機構單位。如果使用者移至新機構,則會變更使用者的存取權。如要進一步瞭解機構架構,請參閱管理說明中心。如要進一步瞭解如何將使用者移至其他機構,請參閱「更新使用者」。
- 新的使用者帳戶必須具備
password
。如果已指定hashFunction
,密碼必須是有效的雜湊鍵。如未指定,密碼必須是明文字元,而且介於 8 到 100 個 ASCII 字元之間。詳情請參閱 API 參考資料。 - 如果使用者採用 Google Workspace 彈性方案,透過這個 API 建立使用者會產生金錢影響,並導致系統向您的客戶帳單帳戶收取費用。詳情請參閱 API 帳單資訊。
- Google Workspace 帳戶可包含您的任何網域。在多個網域帳戶中,其中一個網域的使用者可與其他帳戶網域中的使用者共用服務。如要進一步瞭解多個網域的使用者,請參閱 API 多重網域資訊。
- 可能有相衝突的帳戶。請先確認您打算新增的使用者是否已擁有 Google 帳戶,然後按照步驟操作,避免與這些帳戶相衝突。請參閱尋找並解決相衝突的帳戶。
- 可能是訪客帳戶。如果使用者邀請沒有 Google 帳戶在雲端硬碟進行協作的機構,他們會收到協作者帳戶,格式為訪客「<使用者名稱>@<您的網域>.com」。如果您新增的使用者與協作者帳戶相同的使用者名稱,帳戶將轉換為完整的 Google Workspace 帳戶。並保留目前的雲端硬碟檔案權限。請參閱「與協作者共用文件」。
成功的回應會傳回 HTTP 200 狀態碼。除了狀態碼,回應還會傳回新使用者帳戶的屬性。
更新使用者帳戶
如要更新使用者帳戶,請使用下列 PUT
要求,並附上授權要求中所述的授權。userKey
可以是使用者的主要電子郵件地址、不重複使用者 id
,或該使用者的別名電子郵件地址。
PUT https://admin.googleapis.com/admin/directory/v1/users/userKey
要求和回應主體都包含 User
執行個體。但 Directory API 支援修補語意,因此您只需要在要求中提交更新過的欄位。
要求範例
在以下範例中,系統建立使用者帳戶時,使用者的 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/makeAdmin
JSON 要求
在這個範例中,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 網域 (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" } ], "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如果帳戶擁有多個網域,您可以擷取整個帳戶在過去 20 天內刪除的使用者,並使用以下
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 baseURL 定義,該定義使用等號 (=) 進行填充。這麼做可以簡化網址剖析程序。
- 無論要上傳的相片大小,API 都會按照 96x96 像素的比例縮減大小。
如果您需要透過 JavaScript 建立相容的連結,Google Closure Library 中會包含 Apache 授權發布的 Base64 編碼和解碼函式。
擷取使用者為非管理員
使用者帳戶只能由管理員修改,但網域中的所有使用者都可以讀取使用者個人資料。非管理員使用者可以提出 viewType
參數為 domain_public
的 users.get
或 users.list
要求,藉此擷取使用者的公開個人資料。範圍 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 狀態碼。如要查看已取消刪除的使用者的帳戶,請使用擷取使用者作業。