【问题标题】:Google Sheets : You do not have permission to call DriveApp.getFoldersByNameGoogle 表格:您无权调用 DriveApp.getFoldersByName
【发布时间】:2022-11-04 15:11:55
【问题描述】:

我有一些我正在尝试执行的代码:

function createOrAppendFile(in_Folder, in_FileName, in_Content ) {
  var fileName=in_FileName;
  //var folderName=in_Folder;
  var folderName="TRADEARCHIVE";

  var content = in_Content;

  // get list of folders with matching name
  var folderList = DriveApp.getFoldersByName(folderName);  
  if (folderList.hasNext()) {
    // found matching folder
    var folder = folderList.next();

    // search for files with matching name
    var fileList = folder.getFilesByName(fileName);
   [... snip ...]

我在应用程序脚本.json

{
  "timeZone": "America/Chicago",
  "dependencies": {},
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "webapp": {
    "executeAs": "USER_DEPLOYING",
    "access": "ANYONE_ANONYMOUS"
  },
  "oauthScopes": [
      "https://www.googleapis.com/auth/spreadsheets.readonly",
      "https://www.googleapis.com/auth/userinfo.email",
      "https://www.googleapis.com/auth/spreadsheets",
      "https://www.googleapis.com/auth/script.scriptapp",
      "https://www.googleapis.com/auth/drive.readonly",
      "https://www.googleapis.com/auth/drive"
  ]
}

我收到以下错误:

Nov 4, 2022, 12:28:53 AM    Error   Exception: You do not have permission to call DriveApp.getFoldersByName. Required permissions: (https://www.googleapis.com/auth/drive.readonly || https://www.googleapis.com/auth/drive)
    at createOrAppendFile(Code:33:29)
    at deleteRows(Code:173:11)
    at onMyEdit(Code:390:29)

我究竟做错了什么?任何帮助、提示或建议将不胜感激。

TIA

【问题讨论】:

    标签: google-apps-script google-sheets google-cloud-platform


    【解决方案1】:

    似乎对我有用(在这种情况下)是放置一个“打开”触发器 搜索文件夹的函数。

    Deployment       Event                            Function
    Head             From spreadsheet - On open       createOrAppendFile
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多