با مجموعهها، منظم بمانید
ذخیره و دستهبندی محتوا براساس اولویتهای شما.
سرویس Admin SDK Directory به شما امکان می دهد از API Directory Admin SDK در Apps Script استفاده کنید. این API به مدیران می دهد Google Workspace دامنه ها (از جمله فروشندگان) توانایی مدیریت دستگاه ها، گروه ها، کاربران و سایر نهادها در دامنه های خود.
مرجع
برای اطلاعات دقیق در مورد این سرویس، به مستندات مرجع Admin SDK Directory API مراجعه کنید. مانند همه سرویسهای پیشرفته در Apps Script، سرویس Admin SDK Directory از اشیاء، روشها و پارامترهای مشابه 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('Nousersfound.');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('Userdata:\n%s',JSON.stringify(user,null,2));}catch(err){// TODO (developer)- Handle exception from the APIconsole.log('Failedwitherror%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%screatedwithID%s.',user.primaryEmail,user.id);}catch(err){// TODO (developer)- Handle exception from the APIconsole.log('Failedwitherror%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('Createdalias%sforuser%s.',alias.alias,userEmail);}catch(err){// TODO (developer)- Handle exception from the APIconsole.log('Failedwitherror%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('Nogroupsfound.');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%saddedasamemberofgroup%s.',userEmail,groupEmail);}catch(err){// TODO (developer)- Handle exception from the APIconsole.log('Failedwitherror%s',err.message);}}
تاریخ آخرین بهروزرسانی 2025-01-09 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-01-09 بهوقت ساعت هماهنگ جهانی."],[[["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."]]],[]]