使用JS客户端删除Google Drive文件 [英] Deleting a Google Drive file using JS client

查看:481
本文介绍了使用JS客户端删除Google Drive文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Google云端硬盘文档中的示例。
所以代码是:

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);
    });

该应用程序已正确安装,并且正在使用drive.file作用域。
问题是该文件未被删除。它仍然存在于云端硬盘用户界面中,无法再打开或下载。文件已损坏。

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.

发送的请求不是DELETE https://www.googleapis.com/drive/v2/files/fileId ,如文档中所述。这是POST https://www.googleapis.com/rpc?key=API_KEY 。正文包含一个JSON数组:

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"}]

响应包含一个空的JSON对象。响应中没有错误,页面中没有JS错误。 APIs Explorer成功删除文件。

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.

任何提示?

推荐答案

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);

这篇关于使用JS客户端删除Google Drive文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆