/** * Lists users in a Google Workspace domain. * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list */functionlistUsers(){constoptionalArgs={customer:'my_customer',maxResults:10,orderBy:'email'};try{constresponse=AdminDirectory.Users.list(optionalArgs);constusers=response.users;if(!users||users.length===0){console.log('Nousersfound.');return;}// Print the list of user's full name and emailconsole.log('Users:');for(constuserofusers){console.log('%s(%s)',user.primaryEmail,user.name.fullName);}}catch(err){// TODO (developer)- Handle exception from the Directory APIconsole.log('Failedwitherror%s',err.message);}}
[null,null,["最后更新时间 (UTC):2025-01-27。"],[[["This quickstart demonstrates how to create a Google Apps Script that utilizes the Directory API to list users within a Google Workspace domain."],["Before running the script, ensure you have a Google Workspace account with API access, administrator privileges, and access to Google Drive."],["The provided code snippet needs to be copied into a new Apps Script project and the Admin Directory API needs to be enabled."],["After authorizing access, execute the script to view a list of users' full names and emails in the execution log."],["For production environments, it is recommended to explore authentication and authorization options further, rather than relying on the simplified approach used in the quickstart."]]],[]]