Delete file in Google Drive using Javascript

I am trying to delete a file using the GDriva API for JavaScript. This page seems to come straight out, but it doesn’t work. https://developers.google.com/drive/v2/reference/files/delete

It seems like it should be easy to do.

function deleteFile(fileId) {
  var request = gapi.client.drive.files.delete({
    'fileId': fileId
  });
  request.execute(function(resp) { });
}

But I get "Uncaught TypeError: Can't read the properties of" files "undefined"

Does anyone know what happened? I have all the rights. I can create and update the file, but not delete it.

UPDATE! Found this: Deleting a Google Drive file using the JS client . There seems to be an error in the API. There is a solution that deletes the document so that you cannot find it using the API using the list, but the document will remain in your Google Drive and will be damaged. You can view it, but not delete or open it.

+1
source share
1 answer

It appears that you did not load the client disk library. The error message states that it gapi.client.driveis undefined. You should have a line like:

gapi.client.load('drive', 'v2', function() { /* Loaded */ });

which will load the drive API and determine gapi.client.drive. Make sure you call delete in the callback, or else make sure it is driveloaded before attempting to delete the file.

, @MasNotsram, gapi.client.request delete.

+1

All Articles