gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 04:09:58 25 4
gpt4 key购买 nike

我尝试使用来自 Google 云端硬盘的示例 documentation .所以代码是:

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

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

应用程序安装正确,我正在使用 drive.file 范围。问题是文件没有被删除。它仍然存在于 Drive UI 中,无法再打开或下载。文件已损坏。

正在发送的请求不是 DELETE https://www.googleapis.com/drive/v2/files/fileId正如文档中所述。这是一个帖子 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 错误。 APIs Explorer 成功删除文件。

有什么提示吗?

最佳答案

改用 XMLHttpRequest:

var xmlReq = new XMLHttpRequest();
xmlReq.open('DELETE', 'https://www.googleapis.com/drive/v2/files/' + fileId + '?key=' + apiKey);
xmlReq.setRequestHeader('Authorization', 'Bearer ' + accessToken);

关于javascript - 使用 JS 客户端删除 Google Drive 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15532468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com