首页 > 解决方案 > 如何修复错误“异常:您无权调用 DriveApp.getFiles。所需权限:”

问题描述

问题是错误“异常:您无权调用 DriveApp.getFiles。所需权限:”在“oauthScopes”时显示:[“ https://www.googleapis.com/auth/spreadsheets.readonly ”、“ https ://www.googleapis.com/auth/userinfo.email "] 放在 appscript.js 中。但是当我删除这些 oautScope 时,错误将显示“异常:参数与 isShareableByEditors 的方法签名不匹配。(第 15 行,文件“代码”)”。我正在制作我的所有文件以检查“禁用评论者和查看者的下载、打印和复制选项”。我已经启用了驱动 API。

function test(){
  var files = DriveApp.getFiles();
  while (files.hasNext()) {
    var file = files.next();
    file.isShareableByEditors(false);
  }
}

我希望我在谷歌驱动器上的所有文件都将选中“禁用评论者和查看者下载、打印和复制的选项”。

标签: google-apps-script

解决方案


现在明白了,我将 isShareableByEditors() 更改为 setShareableByEditors()。

更正:

function test(){
  var files = DriveApp.getFiles();
  while (files.hasNext()) {
    var file = files.next();
    file.setShareableByEditors(false);
  }
}

推荐阅读