google-apps-script - 自动从 Google 云端硬盘删除超过 n 天的文件 - 访问被拒绝 : DriveApp

标签 google-apps-script google-api google-drive-api google-oauth

我正在尝试使用此脚本从谷歌驱动器文件夹中删除一些文件 当我运行这段代码时它一直说我的

"Access denied: DriveApp. (line 20, file "Code")Dismiss"

我在互联网上阅读了很多相关内容,并且已经尝试了我看到的所有解决方案!我在脚本编辑器和 google API 控制台开发人员中启用了权限。任何想法?非常感谢你们

function DeleteOldFiles() {
  var Folders = new Array(
    '1RnA55YH_AyPzEVmkAXkaia2iuH17Kkdl'
  );
  var Files;

  Logger.clear();

  for each (var FolderID in Folders) {
    Folder = DriveApp.getFolderById(FolderID)
    Files = Folder.getFiles();

    while (Files.hasNext()) {
      var File = Files.next();

      if (new Date() - File.getLastUpdated() > 1 * 1 * 10 * 10 * 1000) {
        File.setTrashed(true); // Places the file int the Trash folder
        //Drive.Files.remove(File.getId()); // Permanently deletes the file
        Logger.log('File ' + File.getName() + ' was deleted.');
      }

"Access denied: DriveApp. (line 20, file "Code")Dismiss"

但我在 API 控制台中并通过脚本编辑器启用了访问

最佳答案

您需要记住的是,这是私有(private)用户数据。如果您想访问私有(private)用户数据,您需要数据所有者的许可才能访问它。在脚本中启用 API 仅意味着您的脚本将使用该 API,并不意味着用户已授予您访问其数据的权限。

Access denied

这两种情况都意味着您已通过身份验证的用户无权执行您尝试执行的操作。或者您的应用程序尚未被授予任何权限。

Apps Script determines the authorization scopes (like access your Google Sheets files or Gmail) automatically, based on a scan of the code. Code that is commented out can still generate an authorization request. If a script needs authorization, you'll see one of the authorization dialogs shown here when it is run. Read more here Authorization

关于google-apps-script - 自动从 Google 云端硬盘删除超过 n 天的文件 - 访问被拒绝 : DriveApp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54088579/

相关文章:

google-apps-script - 为什么电子表格app.create函数在Google Apps脚本中不起作用?

ruby - 是否可以启用 Google Drive API 上传以在 Google Drive UI 中显示?

android - GoogleAccountCredential + Google Play Services + Refresh Token - 这如何协同工作?

Google Drive 中的 Excel 连接

google-apps-script - 如何从Google Apps脚本传回自定义错误消息?

google-apps-script - 您无权执行该操作

java - 授权在本地工作但不托管

c# - 谷歌+ API : How can I use RefreshTokens to avoid requesting access every time my app launches?

google-api - Google Admin SDK 403 无权访问此资源/API

google-apps-script - 将撇号设置为 Google 表中的变量