使用Javascript删除Google云端硬盘中的文件 [英] Delete file in Google Drive with Javascript

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

问题描述

我正在尝试使用GDriva API for JavaScript删除文件.该页面似乎已直接退出,但无法正常工作. https://developers.google.com/drive/v2/reference/files/删除

I'm trying to delete a file using the GDriva API for JavaScript. This page is quit straight forward it seems, but it doesn't work. https://developers.google.com/drive/v2/reference/files/delete

看起来应该很容易

function deleteFile(fileId) {
  var request = gapi.client.drive.files.delete({
    'fileId': fileId
  });
  request.execute(function(resp) { });
}

但是我收到未捕获的TypeError:无法读取未定义的属性'files'"

But I get "Uncaught TypeError: Cannot read property 'files' of undefined"

有人知道怎么了吗?我拥有所有权限.我可以创建和更新文件,但不能删除它.

Does anyone know what's wrong? I have all permissions right. I can create and update a file but not remove it.

更新! 找到以下内容:使用JS客户端删除Google云端硬盘文件. API中似乎有一个错误.有一种解决方案可以删除文档,以使您无法使用API​​(使用列表)找到该文档,但是该文档将保留在您的Google云端硬盘中,并且已损坏.您可以查看它,但不能删除或打开它.

UPDATE! Found this: Deleting a Google Drive file using JS client. There's seems to be a bug in the API. There's a solution which delete the document so that you can't find it with the API, using list, but the document will remain in your Google Drive and will be corrupted. You can view it but not remove or open it.

推荐答案

听起来好像没有加载驱动器客户端库.您的错误消息说gapi.client.drive未定义.您应该有这样的一行:

Sounds like you didn't load the drive client library. Your error message says that gapi.client.drive is undefined. You should have a line like:

gapi.client.load('drive', 'v2', function() { /* Loaded */ });

,它将加载驱动器API并定义gapi.client.drive.确保在尝试删除文件之前,您在回调中调用了delete,或者确保已加载drive.

which will load the drive API and define gapi.client.drive. Make sure you either call delete in the callback, or otherwise ensure that drive is loaded before trying to delete a file.

或者,就像@MasNotsram提到的那样,您可以只使用gapi.client.request语法来调用delete.

Or, as @MasNotsram mentioned, you could just use the gapi.client.request syntax for calling delete.

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

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