How to get all results (over 100) using batch in gmail

I am using the Gmail API with the java client library.
I want to batch a lot of requests to get a list of messages.
I am doing a test for only one request.
Here's a snippet of code:

    Gmail client = getClient();     
    BatchRequest batch = client.batch();
    // Create the callback.
    JsonBatchCallback<ListMessagesResponse> callback = new JsonBatchCallback<ListMessagesResponse>() {
        public void onSuccess(ListMessagesResponse listMessagesResponse, HttpHeaders responseHeaders) {
            System.out.println(listMessagesResponse.getMessages().size());
            System.out.println(listMessagesResponse.getNextPageToken());
        }
        @Override
        public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
            System.out.println("Error Message: " + e.getMessage());
        }
    };

    client.users().messages().list("me@gmail.com").queue(batch, callback);      
    batch.execute();

      

The problem is that it only fetches 100 messages. I don't want to get the last token and reuse it for the next request, it doesn't make sense since I want to use the bundle.
So how can you get around the (100) limit to get all messages in one batch request?

thank

+3


source to share





All Articles