Martin Vysny
Martin Vysny

Reputation: 3201

Google Drive Java API: next page token always null

I have the following code which lists contents of a directory:

    final Drive.Files.List request = drive.files().list()
            .setQ("trashed=false and ('" + dirid + "' in parents)")
            .setFields("items(title,mimeType,downloadUrl,id)");
    final List<IFile> result = new ArrayList<IFile>();
    do {
        final FileList files = request.execute();
        for (com.google.api.services.drive.model.File file : files.getItems()) {
            final IFile f = toFile(file, directory);
            result.add(f);
        }
        request.setPageToken(files.getNextPageToken());
        // @todo mvy next page token is null????
        log.debug(directory + ": " + result.size() + " files so far, next page token=" + request.getPageToken() + " " + files.getNextPageToken() + " " + files.getNextLink());
    } while (request.getPageToken() != null &&
            request.getPageToken().length() > 0);

If I browse large directory with 206 files, only the first 100 files are returned and the next page token is always null. Is this a bug or am I missing something?

I took the example code from here: https://developers.google.com/drive/v2/reference/files/list

The code above always prints

0B6WQxw8r8n6fRVFBVDhHc3ZGa3M[testing/konky/material-design-icons-2.0/social/drawable-xxhdpi/]: 100 files so far, next page token=null null null

Upvotes: 2

Views: 2000

Answers (1)

Martin Vysny
Martin Vysny

Reputation: 3201

Heh, in my hunt for optimization I only asked Drive to return the items field. If I call

 .setFields("items(title,mimeType,downloadUrl,id),nextPageToken"); 

the token is retrieved correctly.

Upvotes: 9

Related Questions