Google云端硬盘 - 如何从代码中清空垃圾(以编程方式)?

时间:2012-08-14 20:50:41

标签: c# google-drive-api

请帮我将项目与Google云端硬盘集成。 问题是Google云端硬盘文件夹永远不会被清空,因此由于空间不足,Google Drive与桌面同步最终会停止工作。

我需要将垃圾桶配置为不保留已删除的文件(首选选项)或以编程方式从C#代码(不太喜欢)或其他编程语言(最后选项)中清空它。

如何从代码或脚本或其他内容中清空Google云端硬盘垃圾箱?

3 个答案:

答案 0 :(得分:6)

Google云端硬盘API不公开清空垃圾箱的方法,但它有delete方法永久删除文件,而不会将其发送到垃圾箱:

https://developers.google.com/drive/v2/reference/files/delete

您还可以通过查看Files resourcetrashed标签检索垃圾箱中的文件,然后在其上调用delete

答案 1 :(得分:1)

这是一个较短的版本,我尝试使用上述解决方案,但没有运气。

select p.*
from
    (select * from foo limit 2) a,
    prep(a.foo_id,a.foo_range) p;

您所要做的就是在资源菜单中启用de drive api>谷歌高级服务和谷歌开发者的控制台......

答案 2 :(得分:0)

这是一个完整的解决方案:

1)在您的驱动器上创建一个空脚本

2)粘贴以下代码:

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");  
}

3)将脚本部署为Web应用程序

4)单击顶部栏上的时钟并创建一个调用doGet方法的触发器

这将清空正在创建触发器的用户的垃圾箱。