Google Drive - How to remove garbage from code (programmatically)?

Please help me integrate the project with Google Drive. The problem is that the folder with the Google Drive recycle bin is never empty, so in the end, synchronization with Google Desktop stops working due to lack of space.

I need to either configure the garbage so as not to save the deleted files (preferred option), or to programmatically refuse C # code (less preferred) or another programming language (the last resort option).

How can I remove the Google Drive trash from code or script or something else?

+4
c # google-drive-sdk
source share
3 answers

The Google Drive API does not provide a method for removing garbage, but has a delete method for permanently deleting files without sending them to the trash:

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

You can also extract files from the trash by checking the trashed label of the trashed resource, and then call delete on them.

+6
source share

Here's a shorter version, I tried using the above solution, but no luck.

 function emptydrivetrash() { Drive.Files.emptyTrash(); } 

All you have to do is enable the api in the driver, in the menu "Resources" → "Advanced Google Services" and in the Google Developers Console ...

+1
source share

Here is the complete solution:

1) Create an empty script on your disk

2) Paste the following code:

 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) Deploy the script as a web application

4) Click the clock on the top panel and create a trigger that calls the doGet method

This will empty the trash for the user creating the trigger.

0
source share

All Articles