ReferenceError:未定义驱动器

问题描述 投票:0回答:1

我正在尝试使用范围为“https://www.googleapis.com/auth/drive.file”的高级驱动服务来最小化权限。我的应用程序只访问位于我的 Webapp Google 驱动器上的文件,这些文件与传入用户共享,不需要对用户的谷歌驱动器执行任何操作,因此我试图避免请求访问他们所有谷歌文件的权限,这是固有的使用 DriveApp。

**杰森

{
  "timeZone": "America/Los_Angeles",
  "dependencies": {
    "enabledAdvancedServices": []
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "oauthScopes": [
    "https://www.googleapis.com/auth/userinfo.email",
    "https://www.googleapis.com/auth/drive.file"
  ],
  "webapp": {
    "executeAs": "USER_ACCESSING",
    "access": "ANYONE"
  }
}

** App script

 console.log(folderId); // this returns a valid ID
 var folder = Drive.Files.get(folderId);  // this fails, Drive is not defined
 var query = "trashed = false and mimeType != 'application/vnd.google-apps.folder'";
 var files = Drive.Files.list({q: query}).items;

我尝试修改我的 Json 后重新发布,我尝试清除我的缓存,但无济于事。

其他文章建议将 Drive API 添加为服务,但我的目标是远离该 API,因为它需要权限授权。修改脚本以使用 DriveApp 工作完美,但权限请求再次令人发指。

如果我在这里走错了路,请告知。 谢谢大家。

google-apps-script google-drive-api drive
1个回答
0
投票

Drive
是一项高级谷歌服务,需要启用它才能使用api。

DriveApp
也可以与提供的范围
drive.file
一起使用,访问的文件

  • 首先使用谷歌选择器(,需要它自己的范围)或
  • 是使用
    DriveApp.create
  • 之类的方法从此脚本项目创建的
  • 您还可以使用
  • 使用上下文驱动器触发器

参考资料:

© www.soinside.com 2019 - 2024. All rights reserved.