使用 JS 客户端删除 Google Drive 文件

2024-03-26

我尝试使用 Google Drive 中的示例文档 https://developers.google.com/drive/v2/reference/files/delete。 所以代码是:

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

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

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

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

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

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

有什么提示吗?


尝试使用 XMLHttpRequest 代替:

var xmlReq = new XMLHttpRequest();
xmlReq.open('DELETE', 'https://www.googleapis.com/drive/v2/files/' + fileId + '?key=' + apiKey);
xmlReq.setRequestHeader('Authorization', 'Bearer ' + accessToken);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 JS 客户端删除 Google Drive 文件 的相关文章

随机推荐