【问题标题】:Is there a script to empty Google Team Drive Trash Related Folders?是否有清空 Google 团队云端硬盘相关文件夹的脚本?
【发布时间】:2020-01-05 22:07:53
【问题描述】:

如何制作脚本来清空 google 团队驱动器垃圾文件夹?如果我在谷歌驱动器中有三个主要文件夹,它会生成三个主要垃圾文件夹。我怎样才能清空所有这些文件夹?

我发现的所有脚本都只能清空我的驱动器垃圾文件夹。

我已经尝试了很多脚本,你可以看到下面的代码

function createTimeDrivenTriggers() {
  ScriptApp.newTrigger('emptyThrash')
      .timeBased()
      .everyMinutes(1)
      .create();
}
function emptyThrash()
{
Drive.Files.emptyTrash();

}


// I have also tried the script below
function doGet() {
  try{
  authorize();    
  var key = "YOUR DEVELOPER KEY";
  var params = {method:"DELETE",
                oAuthServiceName: "drive",
                oAuthUseToken: "always"
               };  
  UrlFetchApp.fetch("https://www.googleapis.com/drive/v2/files/trash?key="+key,     params);  
  }
  catch(error)
  {
    MailApp.sendEmail("<some email>", "EMPTY TRASH BIN ERROR:<br>"+error);    
    return;
  } 
}

function authorize() {
  var oauthConfig = UrlFetchApp.addOAuthService("drive");
  var scope = "https://www.googleapis.com/auth/drive";
  oauthConfig.setConsumerKey("anonymous");
  oauthConfig.setConsumerSecret("anonymous");
  oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?     scope="+scope);
  oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken");    
  oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");  
}

【问题讨论】:

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


    【解决方案1】:

    无法直接清空 google team drive 垃圾文件夹。

    您可以做的是利用Advanced Drive Service 到list 团队驱动器的垃圾内容,然后永久使用delete 这些内容:

    function myFunction() { 
      var optionalArgs={'driveId':'THE TEAM DRIVE ID', 'includeItemsFromAllDrives':true, 'corpora': 'drive', 'supportsAllDrives': true, 'q':'trashed = true' }  
      var trashed=Drive.Files.list(optionalArgs).items; 
      for(var i=0;i<trashed.length;i++){
        Drive.Files.remove(trashed[i].id, {'supportsAllDrives':true}) 
      }
    }
    

    对于团队驱动器,请确保将 'includeItemsFromAllDrives':true, 'corpora': 'drive', 'supportsAllDrives': true 设置为列表,将 'supportsAllDrives':true 设置为删除文件。要仅查询已删除的文件,请使用 'q':'trashed = true'。

    请注意,所有共享云端硬盘的内容都将被删除 成员并删除它们,您需要具有适当的权限(是 经理或内容经理)。

    【讨论】:

    • 您好 ziganotschka,感谢您的帮助。但是当我尝试该脚本时出现错误:ReferenceError: "Drive" is not set。 (第 3 行,文件“代码”)我们应该先定义“驱动器”吗?我试图将 driveId 放在这个参数中,但也没有成功。
    • 问题是我忘记启用 Drive Api 资源。由于我启用它,脚本运行良好。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    • 2019-02-26
    • 1970-01-01
    • 2017-09-21
    • 2018-06-21
    • 2019-02-28
    • 1970-01-01
    相关资源
    最近更新 更多