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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With