一个Google Script不会授权,其他人会

时间:2016-10-31 05:42:32

标签: google-apps-script

我们最近更改了Google密码,并重新授权了除此之外的所有脚本。

这一个脚本是唯一不会授权的脚本。从编辑器运行它不会要求授权,但执行Web应用程序仍会显示“您必须提供此应用程序运行的授权”错误。

我正在提供链接,请让我知道我还能做些什么。

https://script.google.com/d/1Cb90JPvS2gDn1invg1f4NKErn7urfhJm0vmrkNsjW0trVvHj0NBO8sNK/edit?usp=drive_web

以下是代码。它取出已经过去的“节目”并将它们放入每月电子表格(每月)从工作电子表格中删除它们,因为当工作电子表格中有太多行时,其他谷歌脚本会变慢。 (它还依赖于另一个名为“Global”的脚本。)

var MAX_PROCESSED = 100;

function doGet(e) {
  var app = UiApp.createApplication();
  var start_screen = app.createVerticalPanel();

  var wait_screen = app.createVerticalPanel().setId("screen");

  var gig_sheet = Global.getGigsSheet();
  var max_rows = gig_sheet.getLastRow();
  var max_cols = gig_sheet.getLastColumn();
  var col_descriptions = gig_sheet.getRange(1, 1, 1, max_cols).getValues()[0];
  var col_ids = gig_sheet.getRange(2, 1, 1, max_cols).getValues()[0];

  var cur_date = new Date();
  var archive_filename = "Database archive "+cur_date.toDateString();
  var old_file = SpreadsheetApp.create(archive_filename, 0, max_cols);
  var old_sheet = old_file.getActiveSheet();
  old_file.renameActiveSheet("Database");
  old_sheet.appendRow(col_descriptions);
  old_sheet.appendRow(col_ids);
  SpreadsheetApp.flush();

  var message = (max_rows-2)+ " gigs to examine. ";
  if(max_cols > 500)
    message+= "Hmm... This may take a while. ";

  message+="<br/>New archive database ready \""+archive_filename+"\".  Press start to begin.";

  var id_string = old_file.getId();
  Global.log("doc id:"+id_string);
  var doc_id_widget = app.createHidden("doc_id", id_string);
  var row_pos_widget = app.createHidden("row_pos", 3);
  var old_total_widget = app.createHidden("old_total", max_rows);

  var start_button = app.createButton("Start");
  start_button.addClickHandler(app.createClientHandler().forTargets(start_screen).setVisible(false).forTargets(wait_screen).setVisible(true));
  start_button.addClickHandler(app.createServerHandler('processGigs').addCallbackElement(doc_id_widget).addCallbackElement(row_pos_widget).addCallbackElement(old_total_widget));

  start_screen.add(app.createHTML(message));
  start_screen.add(start_button);

  wait_screen.add(app.createHTML("Working... should take about 60 seconds.  If it goes longer than 6 minutes, Google will display an error anyway."));
  wait_screen.setVisible(false);

  app.add(start_screen);
  app.add(wait_screen);

  return app;
}

function test()
{
  var test;
}

function processGigs(e){

  Global.log("processGigs");
  var app = UiApp.getActiveApplication();

  var row_pos = parseInt(e.parameter.row_pos);
  var id_string = e.parameter.doc_id;
  var old_total = e.parameter.old_total;
  var screen = app.getElementById("screen");
  screen.setVisible(false);

  Global.log("Loading row_pos:"+row_pos+", raw data:"+e.parameter.row_pos);
  Global.log("Spreadsheet ID:"+id_string);

  var gig_sheet = Global.getGigsSheet();
  var max_rows = gig_sheet.getLastRow();
  var max_cols = gig_sheet.getLastColumn();
  var col_descriptions = gig_sheet.getRange(1, 1, 1, max_cols).getValues()[0];
  var col_ids = gig_sheet.getRange(2, 1, 1, max_cols).getValues()[0];

  var old_file = SpreadsheetApp.openById(id_string);
  var old_sheet = old_file.getActiveSheet();

  var cur_date = new Date();
  var existing_date;
  var existing_fee;

  var archive_count= 0;
  var row;
  var range;
  var item;
  var items_processed = 0;

  while (items_processed < MAX_PROCESSED && row_pos <= max_rows){
    Global.log("row_pos:"+row_pos+", max_rows:"+max_rows+", max_cols:"+max_cols);
    range = gig_sheet.getRange(row_pos, 1, 1, max_cols);
    row = range.getValues()[0];
    item = Global.arrayToObject(col_ids, row, false);
    Global.parseValuesOnObject(col_ids, item, false);
    if((item.paid >= item.fee && item.date < cur_date) || item.status == "Cancelled"){
      old_sheet.appendRow(row);
      gig_sheet.deleteRows(row_pos,1);
      max_rows--;
      archive_count++;
    }else{
      row_pos++;
    }
    items_processed++;
  }

  var work_screen = app.createVerticalPanel();
  var wait_screen = app.createVerticalPanel().setId("screen").setVisible(false);
  var message_widget = app.createHTML();
  work_screen.add(message_widget);
  wait_screen.add(app.createHTML("Working... should take about 60 seconds.  If it goes longer than 6 minutes, Google will display an error anyway."));


  Global.log("Saving row_pos:"+row_pos);
  var doc_id_widget = app.createHidden("doc_id", id_string);
  var row_pos_widget = app.createHidden("row_pos", row_pos);
  var old_total_widget = app.createHidden("old_total", old_total);

  var start_button = app.createButton("Continue");
  start_button.addClickHandler(app.createClientHandler().forTargets(work_screen).setVisible(false).forTargets(wait_screen).setVisible(true));
  start_button.addClickHandler(app.createServerHandler('processGigs').addCallbackElement(doc_id_widget).addCallbackElement(row_pos_widget).addCallbackElement(old_total_widget));

  //new_sheet.getRange(1, new_data.length, 1, new_data[0].length).setValues(new_data);
  //old_sheet.getRange(1, old_data.length, 1, old_data[0].length).setValues(old_data);
  var message = archive_count + " gigs archived.</br>";
  if(row_pos < max_rows){
    message += "Process limit reached. "+(max_rows - row_pos)+" to go, so click Continue to keep trying.";
    work_screen.add(start_button);
  }else{
    message += "End of records reached, none left to archive.  You can close this window now.";
  }

  //message +="<br/>row_pos:"+row_pos+", max_rows:"+max_rows;
  message_widget.setHTML(message);

  app.add(work_screen);
  app.add(wait_screen);

  return app;
}

2 个答案:

答案 0 :(得分:0)

通常,我不喜欢依赖其他脚本的脚本,并会尝试将它们保持在一起。仔细检查依赖性脚本是否授权并正确运行。

我能想到的另一件事是去here,找到脚本(旧版本可能已获得授权)并删除它。否则,如果没有帮助,我认为没有足够的信息来提供更深入的答案。

答案 1 :(得分:0)

好的,我把它解决了。因为我们在帐户之间跳转,所以这个脚本有一个不同的&#34;所有者&#34;比其他人。所以现在这个所有者和我们想要运行它的帐户都需要在发布的版本工作之前对其进行授权...

我终于要检查我在发布时的注意事项,有一条通知说“&#34;之前的所有者需要在发布网址之前进行授权”#34;什么的。