Paweł Dąbrowski
Paweł Dąbrowski

Reputation: 81

Get more than 1000 files from Google Drive Api using batch request and nextPageToken in Java

Is it possible to get more than 1000 files from Google Drive Api using batch request and nextPageToken in Java ? Or maybe there is another solution to get large amount of files without nextPageToken using batch request in Java? Right now I'm getting only 460 files.

void prepareDataForGrid(final String rootFileName, UI ui) throws IOException {

    driveService = googleDriveUtils.getDriveService(ui);
    JsonBatchCallback<FileList> callback = new JsonBatchCallback<FileList>() {

        @Override
        public void onSuccess(FileList fileList, HttpHeaders httpHeaders) throws IOException {
            files = fileList.getFiles(); // get only 460 files

        }

        @Override
        public void onFailure(GoogleJsonError googleJsonError, HttpHeaders httpHeaders) throws IOException {
            throw new IOException();
        }
    };

    var batch = driveService.batch();
    driveService.files().list()
            .setQ("trashed = false")
            .setSpaces("drive")
            .setFields("nextPageToken, files(name, id, size, parents, modifiedTime, mimeType, webViewLink, createdTime)")
            .setPageSize(1000)
            .setOrderBy("name")
            .queue(batch, callback);
    batch.execute();
}

Upvotes: 2

Views: 962

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117301

The maximum page size for the files.list method is 1000

enter image description here

If you want additional files you will need to use the nextPageToken in the response and add it to the pageToken of the following response. As this is one request after another i see no way of doing this with batching.

Upvotes: 3

Related Questions