【问题标题】:Deleting a Google Drive file using JS client使用 JS 客户端删除 Google Drive 文件
【发布时间】:2013-03-10 01:46:35
【问题描述】:

我尝试使用来自 Google Drive 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。这是一个 POST 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 已成功删除该文件。

有什么提示吗?

【问题讨论】:

    标签: javascript google-drive-api


    【解决方案1】:

    改用 XMLHttpRequest:

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

    【讨论】:

    • 谢谢。这可以解决问题。我猜 APIs explorer 并没有真正使用 JS 客户端。我已经提交了一个错误,所以希望它很快得到修复。 code.google.com/p/google-api-javascript-client/issues/…
    • 我遇到了这个问题。请参阅我的帖子stackoverflow.com/questions/16522158/…。我可以使用此解决方案删除文档,以便使用列表的 API 无法找到它,但它仍会保留在 Google Drive 中并且已损坏。这意味着我可以看到它,但无法打开或删除它。
    • 我正在使用gapi.client.init 方法初始化google drive api。如何获取 aaccess 令牌?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    相关资源
    最近更新 更多