11

There are several articles, but I am not able to put a code together to run it successfully.

One article I have looked at: Permanently delete file from google drive

I would like to automatically delete the Google Drive trash folder items every hour or so. Prefer every 10 minutes. Google need to implement this useful feature.

tehhowch
  • 9,645
  • 4
  • 24
  • 42
sam juni
  • 131
  • 1
  • 1
  • 5
  • here is another article I attempted to use with no success: http://stackoverflow.com/questions/11960526/google-drive-how-to-empty-trash-from-code-programmatically/11960708#11960708 – sam juni Sep 23 '15 at 20:57
  • Drive.Files.EmptyTrash(); is the method. It works. But I want to make it in a script to auto pilot it. help please – sam juni Sep 24 '15 at 03:45
  • Have a look here: https://github.com/iassael/google-drive-trash-cleaner – Yannis Assael Aug 31 '16 at 18:19

3 Answers3

6

As stated on [ Permanently delete file from google drive ], you can enable the Drive API in order to get access to the method, through Appscript. Take a look at appscript quotas to ensure that your implementation can support calling the API every ten minutes.

You can use this solution:

function createTimeDrivenTriggers() {
  ScriptApp.newTrigger('emptyThrash')
      .timeBased()
      .everyHours(1)
      .create();
}

function emptyThrash()
{
  Drive.Files.emptyTrash();
}
Community
  • 1
  • 1
Rivero
  • 911
  • 1
  • 6
  • 10
  • 1
    Thanks for the help. i get "ReferenceError: "Drive" is not defined. (line 10, file "")" when i run the code via script.google.com. i believe i had similar issue before on top of other issues. so its still not working code. – sam juni Sep 25 '15 at 01:59
  • i forgot to enable Drive API. let me try again and report back. thanks – sam juni Sep 25 '15 at 02:16
2

Just used

function you-can-put-anything-here()

{
  Drive.Files.emptyTrash();
}

then added trigger in google script with email alerts. set trigger to 1 hour and bam it works. to call emptyTrash, Had to enable Drive API to ON under Advanced Google Services and Drive API ENABLED under Google Developer Console. Save the file and it ran without any issues. Thanks Rivero for guidance.

sam juni
  • 131
  • 1
  • 1
  • 5
  • If you turn it on under Advanced Google Services and play your script, it will give you a link to the project in GDC to enable it. I never use GDC so going there first was not helpful. – blindguy Mar 20 '16 at 15:18
1

i succeeded deleting a file from terminal using following curl command.

curl -X Delete -H 'GData-Version: 3.0' -H 'Authorization: Bearer ya29.Ci9rA4GFUvdEbOBtjA9ZPSq9_W7klt5hmyAMf5Jq8R1EdhiJIZwYqAgnjZsWG7SdWQ' https://www.googleapis.com/drive/v2/files/0Bwhnkm8opwXBQVZ5RmZuMWVUTzg
mehmet riza oz
  • 541
  • 6
  • 18