google drive javascript api gapi.client.drive.files undefined

use*_*551 8 google-drive-api google-api-js-client

列出Google云端硬盘文件的JavaScript示例使用gapi.client.drive.files.list().当尝试使用此方法时,我收到错误"无法读取未定义的属性'文件'".

Google Drive API javascript中已经介绍了此问题和解决方法

https://developers.google.com/drive/v2/reference/files/list#try-it下的文档是否有误?或者有没有办法使用API​​描述.

Cla*_*ino 16

JavaScript示例是正确的,但您必须确保gapi.client.drive.files在加载驱动器库时仅使用(以及其他特定于驱动器的资源),即:

gapi.client.load('drive', 'v2', callback);
Run Code Online (Sandbox Code Playgroud)


小智 6

如果写入后它工作正常gapi.client.load('drive', 'v2', callback),那么一切都很好。在我的情况下它不起作用所以我写了下面的代码。

gapi.load('client', function () {
                gapi.client.load('drive', 'v2', function () {
                    var file = gapi.client.drive.files.get({ 'fileId': fileId });
                    file.execute(function (resp) {
                        //Write you code with resp variable
                    });

                });
            });
Run Code Online (Sandbox Code Playgroud)