0

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.

seanpj
  • 6,735
  • 2
  • 33
  • 54
  • See what happens if you get another page (even if the 'last' page was smaller than the page size.) – Zig Mandel Jun 15 '14 at 14:29
  • Did you notice that 'getNextPageToken()' returns null. The new 'rqst.execute()' without a token gets me the same initial set again. – seanpj Jun 15 '14 at 15:37

1 Answers1

2

You need to request the nextPageToken as one of the fields you want to receive. Otherwise, it will appear to be null since its not included in the response.

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
  • Actually, it is my stupidity. The 'getNextPageToken()' is a member of 'FileList list' so it is (NOW) obvious, that if I don't ask for it, I DON'T GET IT (pun intended). – seanpj Jun 17 '14 at 01:10