5

I tried using the example from Google Drive documentation. So the code is :

var request = gapi.client.drive.files.delete({
    'fileId' : someFileId
    });

    request.execute(function(resp) 
    {
        console.log(resp);
    });

The app is installed properly and I'm using drive.file scope. The problem is that the file is not deleted. It is still present in the Drive UI and cannot be opened anymore or downloaded. File is corrupted.

The request being sent is not the DELETE https://www.googleapis.com/drive/v2/files/fileId as was stated in docs. It is a POST https://www.googleapis.com/rpc?key=API_KEY. The body contains a JSON array:

[{"jsonrpc":"2.0","id":"gapiRpc","method":"drive.files.delete","params":{"fileId":"someFileId"},"apiVersion":"v2"}]

Response contains one empty JSON object. There are no errors in the response and there are no JS errors in the page. The APIs Explorer successfully deletes the file.

Any hints?

Boris Jockov
  • 614
  • 1
  • 6
  • 15

1 Answers1

5

Try a XMLHttpRequest instead:

var xmlReq = new XMLHttpRequest();
xmlReq.open('DELETE', 'https://www.googleapis.com/drive/v2/files/' + fileId + '?key=' + apiKey);
xmlReq.setRequestHeader('Authorization', 'Bearer ' + accessToken);
  • 1
    Thanks. This does the trick. I guess APIs explorer doesn't really use JS client. I've submitted a bug so hopefully it gets fixed soon. https://code.google.com/p/google-api-javascript-client/issues/detail?id=77 – Boris Jockov Mar 21 '13 at 16:44
  • I'm having problems with this. See my post, http://stackoverflow.com/questions/16522158/delete-file-in-gdrive-with-javascript. I can remove a document, using this solution, so that it can't be found with API using list, but it will still remain in Google Drive and are corrupted. Meaning I can see it but not open or remove it. – arpo May 14 '13 at 07:02
  • I'm initializing the google drive api with the `gapi.client.init` method. How do i obtain the aaccess token? – Apuleius May 24 '17 at 05:03