本文介绍了是否有脚本可以清空Google Team Drive垃圾桶相关文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何制作一个脚本来清空Google Team Drive垃圾文件夹?如果我在Google云端硬盘中有三个主文件夹,则它会成为三个主要垃圾箱文件夹.如何清空所有这些文件夹?

How can I make a script to empty the google team drive trash folder? If I have three main folders in google drive, it makes three main trash folders. How can I empty all those folders?

我找到的所有脚本仅能清空驱动器回收站文件夹.

All the scripts that I found only manage to empty the my drive trash folder.

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

I have already tried a lot of scripts as you can see the codes below

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 Team Drive垃圾文件夹.

您可以做的是利用高级驱动器服务列表小组驱动器中已破坏的内容,然后永久删除这些内容:

It is not possible to empty the google team drive trash folder directly.

What you can do instead is make use of the Advanced Drive Service to list the trashed contents of the team drive(s) and then permanently delete those contents:

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'.

For team drives, make sure to set 'includeItemsFromAllDrives':true, 'corpora': 'drive', 'supportsAllDrives': true for listing and 'supportsAllDrives':true for removing files. To query for trashed files only, use 'q':'trashed = true'.

这篇关于是否有脚本可以清空Google Team Drive垃圾桶相关文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 17:34