Reputation: 486
I want to execute UserManager.getAllUsers() on a domain with more than 40 000 users. This script runs more than 5 minutes and nevers finishes. Is there any way to split this request like fomr SitesApp.getalldescendants ?
Best regards
Upvotes: 0
Views: 590
Reputation: 3730
Here is a little code which returns account data in CSV string format. To run the code, you will have to be the administrator of Google Apps Domain. You may parse the CSV string and get the required fields
//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"};
}
Upvotes: 0
Reputation: 3730
You may use Google Apps Reporting API for Accounts Report. You can use UrlFetchApp and Oauth together to get the account report. In one call, this can return upto 100, 000 accounts in CSV format. I implemented this in Apps Script around 3 months earlier to get the Disk Usage report of every account in my domain. https://developers.google.com/google-apps/reporting/#Accounts_Report
Upvotes: 0
Reputation: 7965
Please have a look at this issue . Please star it and try the workaround mentioned there.
Upvotes: 1