【问题标题】:How to store values & avoid execution time limit on this Google Drive Script?如何存储值并避免此 Google Drive 脚本的执行时间限制?
【发布时间】:2014-12-23 04:39:55
【问题描述】:

我有一个权限审核 Google 脚本和一个 Google 表格,可以在脚本运行时存储输出。如何让脚本在处理时将条目保存到工作表,同时避免执行时间限制(5 或 6 分钟)?

我正在扫描的 Google Drive 大于 6gb,所以虽然我认为脚本可以提高效率,但达到执行限制可能是不可避免的。

谷歌脚本: /* ======================================= 谁可以查看您在 Google 云端硬盘中的文件 ======================================= 由 Amit Agarwal 于 2014 年 1 月 11 日撰写
教程 :: http://labnol.org/?p=28237 */

function ScanGoogleDrive() {

  var files = DriveApp.getFiles();  
  var timezone = Session.getScriptTimeZone();
  var email = Session.getActiveUser().getEmail();

  var file, date, access, url, permission;
  var privacy, view, viewers, edit, editors;

  var rows = [["File Name", "Who has access?", "Date Created"]];

  while ( files.hasNext() ) {

    file = files.next();

    try {

      access     = file.getSharingAccess();
      permission = file.getSharingPermission();
      viewers    = file.getViewers();      
      editors    = file.getEditors();

      view = [];
      edit = [];

      date =  Utilities.formatDate(file.getDateCreated(), timezone, "yyyy-MM-dd HH:mm")
      url = '<a href="' + file.getUrl() + '">' + file.getName() + '</a>';

      for (var v=0; v<viewers.length; v++) {                
        view.push(viewers[v].getName() + " " + viewers[v].getEmail());
      }

      for (var ed=0; ed<editors.length; ed++) {                
        edit.push(editors[ed].getName() + " " + editors[ed].getEmail());
      }

      switch(access) {
        case DriveApp.Access.PRIVATE:
          privacy = "Private";
          break;
        case DriveApp.Access.ANYONE:
          privacy = "Anyone";
          break;
        case DriveApp.Access.ANYONE_WITH_LINK:
          privacy = "Anyone with a link";
          break;
        case DriveApp.Access.DOMAIN:
          privacy = "Anyone inside domain";
          break;
        case DriveApp.Access.DOMAIN_WITH_LINK:
          privacy = "Anyone inside domain who has the link";
          break;
        default:
          privacy = "Unknown";
      }

      switch(permission) {
        case DriveApp.Permission.COMMENT:
          permission = "can comment";
          break;
        case DriveApp.Permission.VIEW:
          permission = "can view";
          break;
        case DriveApp.Permission.EDIT:
          permission = "can edit";
          break;
        default:
          permission = "";
      }

      view = view.join(", ");

      edit = edit.join(", ");

      privacy += (permission === "" ? "" : " " + permission) 
               + (edit === "" ? "" : ", " + edit + " can edit")
               + (view === "" ? "" : ", " + view + " can view")

      rows.push([url, privacy, date]);

    } catch (e) {Logger.log(e.toString()); Logger.log(file.getName());};

  }

  var html = "<p>File Permissions Report for Google Drive</p>";

  html += "<table><tr><td><b>" + rows[0].join("</b></td><td><b>") + "</b></td></tr>";

  for (var i=1; i<rows.length; i++) {
    html += "<tr><td>" + rows[i].join("</td><td>") + "</td></tr>";
  }

  html += "</table><br>For help, refer to this <a href='http://www.labnol.org/internet/google-drive-access/28237/'>online tutorial</a> written by <a href='http://ctrlq.org/'>Amit Agarwal</a>.";

  MailApp.sendEmail(email, "Google Drive - File Permissions Report", "", {htmlBody: html});

}

谢谢!

【问题讨论】:

    标签: google-apps-script google-sheets google-drive-api google-apps


    【解决方案1】:

    很遗憾,这些限制是由 Google 服务的配额设置的。使用任何 Google 服务的所有脚本都受此类限制的约束。您可以在以下链接中了解更多信息:https://developers.google.com/apps-script/guides/services/quotas

    【讨论】:

      猜你喜欢
      • 2011-01-09
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 2015-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-13
      相关资源
      最近更新 更多