Google API java client - pageSize

我的未来我决定 提交于 2019-12-10 16:29:19

问题


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:


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.



来源:https://stackoverflow.com/questions/30739879/google-api-java-client-pagesize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!