请帮助我与Google Drive集成一个项目。问题是Google Drive的回收站文件夹永远不会被清空,所以最终Google Drive与桌面的同步会因为空间不足而停止工作。
我需要将垃圾桶配置为不保留已删除的文件(首选选项),或者从C#代码(不太首选)或其他编程语言(最后的选项)中编程清空它。
如何从代码或脚本中清空Google Drive垃圾?
发布于 2012-08-15 05:04:44
Google Drive API没有公开一个清空垃圾桶的方法,但它有一个delete
方法来永久删除文件,而不是把它们送进垃圾桶:
https://developers.google.com/drive/v2/reference/files/delete
您还可以通过检查Files resource的trashed
标签从垃圾桶中检索文件,然后对它们调用delete
。
发布于 2016-06-21 02:36:28
这里是一个简短的版本,我尝试使用上面的解决方案,但没有成功。
function emptydrivetrash() {
Drive.Files.emptyTrash();
}
您所要做的就是在资源菜单-> Google高级服务和google开发者控制台中启用de drive api。
发布于 2014-07-08 19:35:39
这是一个完整的解决方案:
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方法的触发器
这将为创建触发器的用户清空回收站。
https://stackoverflow.com/questions/11960526
复制相似问题