Reputation: 1889
I'm trying to delete a file using the GDriva API for JavaScript. This page is quit straight forward it seems, but it doesn't work. https://developers.google.com/drive/v2/reference/files/delete
Looks 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: Cannot read property 'files' of undefined"
Does anyone know what's wrong? I have all permissions right. I can create and update a file but not remove it.
UPDATE! Found this: Deleting a Google Drive file using JS client. There's seems to be a bug in the API. There's a solution which delete the document so that you can't find it with the API, using list, but the document will remain in your Google Drive and will be corrupted. You can view it but not remove or open it.
Upvotes: 2
Views: 3479
Reputation: 9449
Sounds like you didn't load the drive client library. Your error message says that gapi.client.drive
is undefined. You should have a line like:
gapi.client.load('drive', 'v2', function() { /* Loaded */ });
which will load the drive API and define gapi.client.drive
. Make sure you either call delete in the callback, or otherwise ensure that drive
is loaded before trying to delete a file.
Or, as @MasNotsram mentioned, you could just use the gapi.client.request syntax for calling delete.
Upvotes: 3