2012-07-03 53 views
0

我想在一个拥有40,000多个用户的域上执行UserManager.getAllUsers()。该脚本运行超过5分钟,nevers完成。有什么办法可以将这个请求分割为SitesApp.getalldescendants吗?UserManager.getAllUsers()on large domain

问候

+0

以下是你需要使用配置API答案:http://stackoverflow.com/questions/11416482/so​​lved-api-provisioning-properties-account –

回答

1

请看看this issue。请将其列出并尝试在那里提到的解决方法。

+0

谢谢为你的答案 –

+0

如果你对答案感到满意,请将它标记为已回答 – Srik

0

您可以使用Google Apps Reporting API进行帐户报告。您可以一起使用UrlFetchApp和Oauth来获取帐户报告。在一次通话中,这可以以CSV格式返回多达100,000个帐户。我在大约3个月前在Apps Script中实现了此功能,以获取我的域中每个帐户的“磁盘使用情况”报告。 https://developers.google.com/google-apps/reporting/#Accounts_Report

+0

嗨Wagar,你能用一些代码来说明吗? –

+0

@Sergeinsas我在这个线程中的下一个答案说明了与示例代码相同 –

+0

谢谢,这将对我有用:-) –

0

这是一个以CSV字符串格式返回账户数据的小代码。要运行代码,您必须成为Google Apps Domain的管理员。您可以解析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"}; 
    }