Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The JavaScript example to list files of Google Drive uses gapi.client.drive.files.list(). When trying to use this method I get the error "Cannot read property 'files' of undefined".

The issue and a workaround are already described under Google Drive API javascript

Is the documentation under https://developers.google.com/drive/v2/reference/files/list#try-it incorrect? Or is there a way to use the API as described.

like image 380
user1495551 Avatar asked Jan 10 '13 16:01

user1495551


People also ask

How do I create a Google Drive folder in Google Drive API?

To create a folder, use the files. create method with the application/vnd. google-apps. folder MIME type and a title.


2 Answers

The JavaScript example is correct, but you have to make sure that you only use gapi.client.drive.files (and the other Drive-specific resources) when the Drive library is loaded, i.e. after:

gapi.client.load('drive', 'v2', callback);
like image 62
Claudio Cherubino Avatar answered Oct 18 '22 11:10

Claudio Cherubino


If it works fine after writing gapi.client.load('drive', 'v2', callback), then all good. In my case it does not work so I wrote below code.

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
                    });

                });
            });
like image 32
Animesh Santoki Avatar answered Oct 18 '22 13:10

Animesh Santoki