我想在拥有超过40,000个用户的域上执行UserManager.getAllUsers()。这个脚本运行超过5分钟,并且完成。有没有办法像fomr SitesApp.getalldescendants一样分割这个请求?
祝你好运
答案 0 :(得分:1)
请查看this issue。请注明并尝试那里提到的解决方法。
答案 1 :(得分:0)
您可以将Google Apps Reporting API用于帐户报告。您可以一起使用UrlFetchApp和Oauth来获取帐户报告。在一次通话中,这可以以CSV格式返回多达100,000个帐户。我在3个月前在Apps脚本中实现了这一点,以获取我域中每个帐户的磁盘使用情况报告。 https://developers.google.com/google-apps/reporting/#Accounts_Report
答案 2 :(得分:0)
这是一个以CSV字符串格式返回帐户数据的小代码。要运行代码,您必须是Google Apps域的管理员。您可以解析CSV字符串并获取必填字段
//Refernce API URL
// https://developers.google.com/google-apps/reporting/#accounts_report
function startHere(){
var domain = UserManager.getDomain();
var fDate = Utilities.formatDate(new Date(), Session.getTimeZone(), 'yyyy-MM-dd');
var url = 'https://www.google.com/hosted/services/v1.0/reports/ReportingData';
var fetchArgs = googleOAuth_('Reporting', url);
fetchArgs.method = 'POST';
var rawXML = '<?xml version="1.0" encoding="UTF-8"?>'
+'<rest xmlns="google:accounts:rest:protocol" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance ">'
+'<type>Report</type>'
+'<domain>'+domain+'</domain>'
+'<date>'+fDate+'</date>'
+'<page>1</page>'
+'<reportType>daily</reportType>'
+'<reportName>accounts</reportName>'
+'</rest>';
fetchArgs.payload = rawXML;
//fetchArgs.contentType = "application/xml";
fetchArgs.headers = {"Content-type": "application/atom+xml charset=UTF-8"};
var csvData = UrlFetchApp.fetch(url, fetchArgs).getContentText();
}
//Google oAuth, helper function
function googleOAuth_(name,scope) {
var oAuthConfig = UrlFetchApp.addOAuthService(name);
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey("anonymous");
oAuthConfig.setConsumerSecret("anonymous");
return {oAuthServiceName:name, oAuthUseToken:"always"};
}