无法使用 Drive API 在 Google Apps 脚本中获取文件

阿德里亚诺_皮纳福

我有一个谷歌应用程序脚本(我在我的一个电子表格中使用)。我习惯于调用 DriveApp 服务来处理文件(列表、创建、移动等),但我想获取上次修改文件的用户。在多个地方查找后,我了解到实现这一目标的唯一方法是将 Drive API SDK(高级驱动器服务)导入 Google Apps 脚本。我使用官方文档添加了它所以,这就是我被困的地方。为了简化,请看下面的代码:

console.log(DriveApp.getFileById('1eMIUTEmpvzN5a3kK6PWbK4W8RCkbNOSxxxxxxxxxxx').getName())
console.log(Drive.Files.get('1eMIUTEmpvzN5a3kK6PWbK4W8RCkbNOSxxxxxxxxxxx').title)

第一个显示我的文件名就好了。第二个失败:

GoogleJsonResponseException:对 drive.files.get 的 API 调用失败,错误:找不到文件:1eMIUTEmpvzN5a3kK6PWbK4W8RCkbNOSxxxxxxxxxxx

(匿名)@ List Files.gs:2

任何想法为什么它不起作用?

Tanaike

根据您的脚本和错误File not found,我认为在您的情况下,该文件可能会放在共享驱动器中。如果我的理解是正确的,就会发生这样的错误。另一方面,当DriveApp.getFileById使用时,可以检索共享驱动器中的文件。那么在你的情况下,下面的修改怎么样?

从:

console.log(Drive.Files.get('1eMIUTEmpvzN5a3kK6PWbK4W8RCkbNOSxxxxxxxxxxx').title)

到:

console.log(Drive.Files.get('1eMIUTEmpvzN5a3kK6PWbK4W8RCkbNOSxxxxxxxxxxx', {supportsAllDrives: true}).title)

参考:

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用 Google Apps 脚本将文件上传到 Google Drive

无法使用Google Drive API获取所有文件的列表

使用Google Apps脚本获取Instagram API

如何使用Apps脚本基于“未知”条件进行过滤,从而从Google Drive获取文件?

使用Google Drive API获取文件大小

如何在Google Apps脚本中使用UrlFetchApp发出Drive API批处理请求

Google Apps脚本网络应用的Drive API推送通知

Google Apps 脚本中的 Google Drive 通知

使用NodeJS在Google Drive API中获取特定文件的内容

使用 pydrive 或 google drive api 在 google drive 中复制文件

无法使用 Google Apps 脚本更新 contactusgin People api

无法使用 Google Apps 脚本获取

使用Google Drive API在指定的Google Drive中上传文件

使用 Google Apps 脚本将 JSON 文件写入和检索到 Google Drive

Google 脚本:使用 Drive API 添加评论

Google Team Drive使用Apps脚本在团队驱动器文件夹之间移动文件

Drive API V3:使用 Google Apps 脚本的多块可恢复上传文件大小错误(缺少 2 个字节)

使用Google-Drive-API移动文件

如何使用Google Drive API上传文件?

使用google-drive-api python获取文件的链接

如何在 Apps 脚本中使用 sendMail 功能附加 Google Drive 文件?

如何使用Java中的Google Drive API v3获取上载文件到Google Drive的可共享链接

如何使用google drive api获取google drive中所有文件的名称?

使用Google Drive API上传文件夹中的文件

Google Apps脚本从外部API获取响应

未使用 Google Drive API 获取共享文件夹中的项目列表

是否可以使用Google Drive API列出Google Drive中指定目录中的文件?

如何使用Google Drive Javascript API更新Google Drive中的zip文件

使用Google Drive API上传PDF文件-Google Drive Web Client中没有预览