Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Служба каталогов Admin SDK позволяет использовать API каталогов Admin SDK в Apps Script. Этот API предоставляет администраторам Google Workspace домены (включая реселлеров) возможность управлять устройствами, группами, пользователями и другими сущностями в своих доменах.
Ссылка
Подробную информацию об этой службе см. в справочной документации по API каталога Admin SDK. Как и все расширенные службы в Apps Script, служба каталога Admin SDK использует те же объекты, методы и параметры, что и общедоступный API. Подробнее см. в разделе «Как определяются сигнатуры методов» .
/** * Lists all the users in a domain sorted by first name. * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list */functionlistAllUsers(){letpageToken;letpage;do{page=AdminDirectory.Users.list({domain:'example.com',orderBy:'givenName',maxResults:100,pageToken:pageToken});constusers=page.users;if(!users){console.log('No users found.');return;}// Print the user's full name and email.for(constuserofusers){console.log('%s (%s)',user.name.fullName,user.primaryEmail);}pageToken=page.nextPageToken;}while(pageToken);}
Получить пользователя
Этот пример получает пользователя по его адресу электронной почты и регистрирует все его данные в виде строки JSON.
/** * Get a user by their email address and logs all of their data as a JSON string. * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/get */functiongetUser(){// TODO (developer) - Replace userEmail value with yoursconstuserEmail='liz@example.com';try{constuser=AdminDirectory.Users.get(userEmail);console.log('User data:\n %s',JSON.stringify(user,null,2));}catch(err){// TODO (developer)- Handle exception from the APIconsole.log('Failed with error %s',err.message);}}
Добавить пользователя
Этот пример добавляет нового пользователя в домен, включая только необходимую информацию. Полный список полей пользователя см. в справочной документации API.
/** * Adds a new user to the domain, including only the required information. For * the full list of user fields, see the API's reference documentation: * @see https://developers.google.com/admin-sdk/directory/v1/reference/users/insert */functionaddUser(){letuser={// TODO (developer) - Replace primaryEmail value with yoursprimaryEmail:'liz@example.com',name:{givenName:'Elizabeth',familyName:'Smith'},// Generate a random password string.password:Math.random().toString(36)};try{user=AdminDirectory.Users.insert(user);console.log('User %s created with ID %s.',user.primaryEmail,user.id);}catch(err){// TODO (developer)- Handle exception from the APIconsole.log('Failed with error %s',err.message);}}
Создать псевдоним
В этом примере создается псевдоним (никнейм) для пользователя.
/** * Creates an alias (nickname) for a user. * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/users.aliases/insert */functioncreateAlias(){// TODO (developer) - Replace userEmail value with yoursconstuserEmail='liz@example.com';letalias={alias:'chica@example.com'};try{alias=AdminDirectory.Users.Aliases.insert(alias,userEmail);console.log('Created alias %s for user %s.',alias.alias,userEmail);}catch(err){// TODO (developer)- Handle exception from the APIconsole.log('Failed with error %s',err.message);}}
/** * Lists all the groups in the domain. * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups/list */functionlistAllGroups(){letpageToken;letpage;do{page=AdminDirectory.Groups.list({domain:'example.com',maxResults:100,pageToken:pageToken});constgroups=page.groups;if(!groups){console.log('No groups found.');return;}// Print group name and email.for(constgroupofgroups){console.log('%s (%s)',group.name,group.email);}pageToken=page.nextPageToken;}while(pageToken);}
Добавить участника группы
В этом примере пользователь добавляется в существующую группу в домене.
/** * Adds a user to an existing group in the domain. * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/members/insert */functionaddGroupMember(){// TODO (developer) - Replace userEmail value with yoursconstuserEmail='liz@example.com';// TODO (developer) - Replace groupEmail value with yoursconstgroupEmail='bookclub@example.com';constmember={email:userEmail,role:'MEMBER'};try{AdminDirectory.Members.insert(member,groupEmail);console.log('User %s added as a member of group %s.',userEmail,groupEmail);}catch(err){// TODO (developer)- Handle exception from the APIconsole.log('Failed with error %s',err.message);}}
[[["Прост для понимания","easyToUnderstand","thumb-up"],["Помог мне решить мою проблему","solvedMyProblem","thumb-up"],["Другое","otherUp","thumb-up"]],[["Отсутствует нужная мне информация","missingTheInformationINeed","thumb-down"],["Слишком сложен/слишком много шагов","tooComplicatedTooManySteps","thumb-down"],["Устарел","outOfDate","thumb-down"],["Проблема с переводом текста","translationIssue","thumb-down"],["Проблемы образцов/кода","samplesCodeIssue","thumb-down"],["Другое","otherDown","thumb-down"]],["Последнее обновление: 2025-07-24 UTC."],[[["The Admin SDK Directory service enables Google Workspace administrators to manage domain resources like users, groups, and devices within Apps Script using the Directory API."],["This advanced service requires enabling both the Admin SDK and the specific service before use, and it mirrors the functionality of the public Directory API."],["Sample code snippets demonstrate common tasks like listing and managing users, creating aliases, and handling groups and their members via the Admin SDK Directory service."],["Before using the sample code, remember to enable the Admin SDK, replace placeholder values with your specific data, and refer to the documentation for details on API usage and error handling."]]],[]]