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

前端 未结 2 1437
遥遥无期
遥遥无期 2020-12-31 17:26

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

相关标签:
2条回答
  • 2020-12-31 17:45

    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
                        });
    
                    });
                });
    
    0 讨论(0)
  • 2020-12-31 18:03

    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);
    
    0 讨论(0)
提交回复
热议问题