尝试从 Google 应用程序脚本中注销选定帐户时,它向我显示错误:发生错误:对 directory.users.signOut 的 API 调用失败并出现错误:请求的身份验证范围不足。我是 G Suite 帐户的管理员。代码:
function signout_user(){
var mailSent = false;
try {
var pageToken, page;
do { //iterate for each page
page = AdminDirectory.Users.list({
domain: 'myshala.com',
orderBy: 'givenName',
pageToken: pageToken
});
var users = page.users;
//Logger.log(users[0].primaryEmail);
for (var i = 0; i < users.length; i++) {
if (users[i].primaryEmail == 'xxxxx@gmail.com') {
//Logger.log(users[i].primaryEmail);
AdminDirectory.Users.signOut(users[i].primaryEmail);
break;
}
}
pageToken = page.nextPageToken;
} while (pageToken);
} // CLOSE try
//Catch if any error occurs
catch(e){
//Log the error
Logger.log('--------------------------------------------------------');
Logger.log('Error occured: '+e.message);
}
if(!mailSent){
//if execution successful
Logger.log('--------------------------------------------------------');
Logger.log('Execution ended. Script completed successfully');
}
}