使用Google App脚本获取随机权限错误,如何调试?

时间:2019-05-30 01:25:03

标签: google-apps-script

我使用一堆访问我的电子表格和Google驱动器的代码进行了库。我对其进行了测试,但它仍然有效,但现在不起作用。我阅读了20条关于如何解决该问题的SO线程,但没有任何效果。我该如何调试?

我收到此错误“您无权调用DriveApp.getFolderById。所需权限:(https://www.googleapis.com/auth/drive.readonly || https://www.googleapis.com/auth/drive) ”以及“ SpreadsheetApp.getActiveSheet”的相同错误。删除并重新授权代码时,它似乎是间歇性的。这些授权存储在哪里?

这是我的代码:

function onOpen(e) {
  SpreadsheetApp.getUi()
    .createMenu("Scripts")
    .addItem("Sync Drive", "GAppsUtils.syncDrive")
    .addItem("Download Selected Scripts", "GAppsUtils.downloadSelectedScripts")
    .addToUi()
}

在我的“ GAppsUtils”库中:

function copyFilesToFolder(files, folder) {
  for (var i in files) {
    var file = files[i]
    file.makeCopy(file.getName(), folder)
  }

  return folder
}

function createTempFolderFromFiles(files) {
  var tempFolder = DriveApp.getFolderById(FOLDERS.TEMP)
  var tempSubFolder = tempFolder.createFolder('download_' + Date.now())
  copyFilesToFolder(files, tempSubFolder)
  return tempSubFolder
}

function getSelectedCellValues() {
  var activeSheet = SpreadsheetApp.getActiveSheet()
  var selection = activeSheet.getSelection()
  var selectionValues = selection.getActiveRange().getValues()

  var range = selection.getActiveRange()
  var firstRowIndex = range.getRow()

  var unfilteredSelectionValues = []
  for (var i in selectionValues) {
    i = Number(i)
    if (!activeSheet.isRowHiddenByFilter(i + firstRowIndex)) {
      unfilteredSelectionValues.push(selectionValues[i])
    }
  }

  return unfilteredSelectionValues
}

function downloadSelectedScripts() {
  var selectedValues = getSelectedCellValues()
  var scriptFileNames = selectedValuesToScriptFileNames(selectedValues)
  var scriptFiles = getScriptFiles(scriptFileNames)
  var tempFolder = createTempFolderFromFiles(scriptFiles)
  Browser.msgBox(tempFolder.getUrl())
}

0 个答案:

没有答案