In an Android app, I'm trying to list files from the Drive, using the RESTful API.
https://developers.google.com/drive/v2/reference/files/list
I have 332 (number is just for example) files in the Google Drive and I run the following code snippet (taken directly from the doc above), trying to list them:
private com.google.api.services.drive.Drive _svc;
...
Files.List rqst = _svc.files().list(); //.setFields("items(title, id)").setMaxResults(90);
do try {
FileList list = rqst.execute();
Log.i("TAG", "count: " + list.getItems().size());
rqst.setPageToken(list.getNextPageToken());
} catch (IOException e) { rqst.setPageToken(null); }
while (rqst.getPageToken() != null && rqst.getPageToken().length() > 0);
if I use plain request:
_svc.files().list();
the loop produces paged results as expected, i.e. 100 + 100 + 100 + 32 files
Adding additional modifier:
_svc.files().list().setFields("items(title, id)");
gives me only the first page of 100 results. The 'getNextPageToken()' produces NULL, indicating no more data available.
Needles to say that using "setMaxResults()" modifier produces the same results. For instance, if I add 'setMaxResults(90)',
_svc.files().list().setMaxResults(90);
produces 90+90+90+62 = 332 files, but
_svc.files().list().setMaxResults(90).setFields("items(title, id)");
yields only 90 files, with no more pages available.
I am assuming that I must be doing something wrong, since I find it unlikely that I would discover a bug never reported (after googling for hours) in an interface that has been around for ages now.