【问题标题】:How do I clear my trashed files in google drive using a script?如何使用脚本清除谷歌驱动器中的垃圾文件?
【发布时间】:2016-06-13 04:17:29
【问题描述】:

我创建了一个谷歌脚本函数来清除我的垃圾文件。我试着运行它,它什么也没做。也没有日志。

function clearTrashed() {
  var files2 = DriveApp.getFiles();
  while (files2.hasNext()) {
    var currentFile2 = files2.next();
    if (currentFile2.isTrashed()) {
      Drive.Files.remove(currentFile2.getId());
      Logger.log("Deleted file: " + currentFile2.getName());
    }
  }
}

我还在我的谷歌开发者控制台和高级谷歌服务中启用了 Drive Api。它看不到任何垃圾文件,否则它会记录它们。会添加标签 google-script 但没有足够的代表

【问题讨论】:

    标签: javascript google-drive-api


    【解决方案1】:

    您可以使用Files: emptyTrash通过发送HTTP请求来永久删除用户的所有垃圾文件:

    DELETE https://www.googleapis.com/drive/v3/files/trash
    

    要使用此功能,您需要启用 Drive API 服务,请注意此请求需要以下范围的授权:

    https://www.googleapis.com/auth/drive
    

    这篇 SO 帖子 - Permanently delete file from google drive 也可能有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-24
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多