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

11,138

Solution 1

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

Solution 2

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

                });
            });
Share:
11,138
Admin
Author by

Admin

Updated on July 22, 2022

Comments