Admin SDK 群組設定服務

Admin SDK 群組設定服務可讓您在 Apps Script 中使用 Admin SDK 的 Groups Settings API。這個 API 可讓 Google Workspace 網域 (包括經銷商) 的管理員在 Google Workspace 帳戶中管理群組設定。

參考資料

如要進一步瞭解這項服務,請參閱 Admin SDK Groups Settings API 的參考說明文件。和 Apps Script 的所有進階服務一樣,Admin SDK 群組設定服務會使用與公用 API 相同的物件、方法和參數。詳情請參閱「如何判定方法簽章」一文。

如要回報問題及尋找其他支援,請參閱 Admin SDK 群組設定支援指南

程式碼範例

下方程式碼範例使用第 1 版的 API。

取得群組設定

這個範例會取得群組的設定,並記錄到控制台。

advanced/adminSDK.gs
/**
 * Gets a group's settings and logs them to the console.
 */
function getGroupSettings() {
  // TODO (developer) - Replace groupId value with yours
  const groupId = 'exampleGroup@example.com';
  try {
    const group = AdminGroupsSettings.Groups.get(groupId);
    console.log(JSON.stringify(group, null, 2));
  } catch (err) {
    // TODO (developer)- Handle exception from the API
    console.log('Failed with error %s', err.message);
  }
}

更新群組設定

以下範例說明群組設定的變更方式。這裡的說明是修改的,但其他各種設定可以透過相同的方式變更。

advanced/adminSDK.gs
/**
 * Updates group's settings. Here, the description is modified, but various
 * other settings can be changed in the same way.
 * @see https://developers.google.com/admin-sdk/groups-settings/v1/reference/groups/patch
 */
function updateGroupSettings() {
  const groupId = 'exampleGroup@example.com';
  try {
    const group = AdminGroupsSettings.newGroups();
    group.description = 'Newly changed group description';
    AdminGroupsSettings.Groups.patch(group, groupId);
  } catch (err) {
    // TODO (developer)- Handle exception from the API
    console.log('Failed with error %s', err.message);
  }
}