/** * List login events for a Google Workspace domain. * @see https://developers.google.com/admin-sdk/reports/reference/rest/v1/activities/list */functionlistLogins(){constuserKey='all';constapplicationName='login';constoptionalArgs={maxResults:10};try{constresponse=AdminReports.Activities.list(userKey,applicationName,optionalArgs);constactivities=response.items;if(!activities||activities.length===0){console.log('Nologinsfound.');return;}// Print login eventsconsole.log('Logins:');for(constactivityofactivities){console.log('%s:%s(%s)',activity.id.time,activity.actor.email,activity.events[0].name);}}catch(err){// TODO (developer)- Handle exception from the Report APIconsole.log('Failedwitherror%s',err.message);}}
[null,null,["最后更新时间 (UTC):2025-01-29。"],[[["This quickstart demonstrates how to use Google Apps Script to access the Admin SDK Reports API and list login events for a Google Workspace domain."],["Before running the script, you will need a Google Workspace domain with API access enabled, a Google Account with administrator privileges, and access to Google Drive."],["The script uses a simplified authentication approach for testing; for production environments, review authentication and authorization best practices before selecting credentials."],["To run the script, you need to enable the Admin SDK API within the Apps Script project and authorize access when prompted."],["After successful execution, the script will output login events to the execution log in the Apps Script editor."]]],[]]