Google API java client - pageSize

574 views Asked by At

Why does service.list().setPageSize(pageSize) not work? It does not return list of elements with specified pageSize. Where is the problem?

EDIT

Here is example of code that does not work:

Appsactivity.Activities.List request = service.activities().list()
        .setDriveFileId(fileId)
        .setGroupingStrategy("driveUi")
        .setSource("drive.google.com")
        .setUserId("me")
        .setPageSize(pageSize);

ListActivitiesResponse response = request.execute();

do {
   response = request.execute();
   List<Activity> items = response.getActivities();        
   System.out.println(items.size());
   request.setPageToken(response.getNextPageToken());

} while (request.getPageToken() != null && request.getPageToken().length() > 0);

If I have 7 activities and pageSize = 3 than it does not return pages 3, 3, 1 as expected, but instead of it returns pages of size 6, 1.

The same problem is discussed here Issue with Google Charts API while paging table but setting pageSize directly via .set("pageSize", pageSize) and .set("page", "enable") did not help.

Another question like this app-engine-java-api-pagesize

1

There are 1 answers

0
lakshayg On

I'm not sure as I am new to Google API. I have used it with Python. I think you need to append the command with .execute() and use service.list().setPageSize(pageSize).execute() . Here is the link to the source code for the script I wrote using Gmail API.