通过Google Apps脚本授予对Google Drive的文件访问权限

时间:2018-12-19 14:35:00

标签: javascript google-apps-script google-drive-api google-form

我有一个带有脚本的表格,该表格将访问电子表格并将其从表格写入电子表格。我的表单具有文件上传功能,并通过电子邮件向用户发送访问我的Google驱动器上文件的链接。不幸的是,用户必须先请求访问权限,然后才能访问文件。无论如何,是否可以让用户无需手动授予权限即可访问我的文件?下面是我的代码:

  function OnSubmit(e) {
  var form = FormApp.getActiveForm();
  var responses = e.response;
  var NameArea = responses.getItemResponses()[0].getResponse();
  var PurchaseRequest = responses.getItemResponses()[1].getResponse();
  var Quantity = responses.getItemResponses()[2].getResponse();
  var Quotation = responses.getItemResponses()[3].getResponse();

  var sheet = SpreadsheetApp.openById('1TKxnfi5LSzznTbjlnqiuSjwvhRmu9Sv1gIiZSDBPlaM');
  var ss = sheet.getSheetByName('2018');
  var data = ss.getDataRange().getValues();
  var lastRow = ss.getLastRow();
  var NextRow = lastRow+1;
  var SSNameArea, SSPurchaseRequest, SSQuantity,SSQuotation;
  var i = 0;
  var j;
  var PurchaseRequestArr = [];
  var QuantityArr = [];
  var dFile;

  PurchaseRequestArr = PurchaseRequest.split(";");
  QuantityArr = Quantity.split(";");

  var PurchaseRequestArrLength = PurchaseRequestArr.length;
  var PurchaseRequestRow = NextRow + PurchaseRequestArrLength;

  do{
    for (j=NextRow;j<PurchaseRequestRow;j++){
      SSNameArea = ss.getRange(j, 3);
      SSPurchaseRequest = ss.getRange(j, 4);
      SSQuantity = ss.getRange(j, 5);
      SSQuotation = ss.getRange(j, 6);
      SSNameArea.setValue(NameArea);
      SSPurchaseRequest.setValue(PurchaseRequestArr[i]);
      SSQuantity.setValue(QuantityArr[i]);
      //dFile = DriveApp.getFileById(Quotation);
      SSQuotation.setValue("https://drive.google.com/open?id=" + Quotation);
      i++;
      //dFile = DriveApp.getFileById(SSQuotation.setValue(Quotation));
    }
  }
  while(i<PurchaseRequestArrLength);
  MailApp.sendEmail('xxx@gmail.com','subject',"https://drive.google.com/open?id=" + Quotation);

}

0 个答案:

没有答案