Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google drive api, javascript list files returns nothing

I'm just getting started with Drive API calls, and I'm trying to list my files.

So far, my function looks like this:

 var retrieveAllFiles = function () {
            var retrievePageOfFiles = function(request, result) {
                request.execute(function(resp) {
                    console.log(resp);
                    result = result.concat(resp.items);
                    var nextPageToken = resp.nextPageToken;
                    console.log("nextPageToken ="+nextPageToken);
                    if (nextPageToken) {
                        request = gapi.client.drive.files.list({'pageToken': nextPageToken});
                        retrievePageOfFiles(request, result);
                    } else {
                        printFileList(result);
                    }
                });
            }
        var initialRequest = gapi.client.drive.files.list({'maxResults': 10});
        console.log("initialRequest = "+initialRequest);
         retrievePageOfFiles(initialRequest, []);
        }

In firebug, I see that the response looks like this:

[
 {
  "id": "gapiRpc",
  "result": {
  "kind": "drive#fileList",
  "etag": "\"vGmlhiWxP02tugPmRvLynwC_A0Y/vyGp6PvFo4RvsFtPoIWeCReyIC8\""
  }
 }
]

This isn't what I expect, because my Drive contains two files.

Can anyone point out what my mistake is?

Thanks

like image 722
rvabdn Avatar asked Mar 24 '23 08:03

rvabdn


1 Answers

I've solved this one myself it was a problem with scopes.

I was using

https://www.googleapis.com/auth/drive.file

but this only grants access to files create with the app making the request. To get access to all the files I had to add

https://www.googleapis.com/auth/drive

I only figured it out by using another app and noticing it was asking for different scopes.

like image 60
rvabdn Avatar answered Apr 02 '23 19:04

rvabdn