首页 > 解决方案 > How to set "pageSize" with the java client of the Google Photos API

问题描述

We are using the Google Photos API java client on Android to retrieve some of the user's photo with this code:

try(PhotosLibraryClient photosLibraryClient = PhotosLibraryClient.initialize(settings)) {
    InternalPhotosLibraryClient.SearchMediaItemsPagedResponse libraryResponse = photosLibraryClient.searchMediaItems(filters);
    Iterable<InternalPhotosLibraryClient.SearchMediaItemsPage> listMediaItemsPage = libraryResponse.iteratePages();

    for (InternalPhotosLibraryClient.SearchMediaItemsPage mediaItemsPage : listMediaItemsPage) {
    /* ... */
    }
}

Our problem is that the mediaItemsPage only retrieve up to 25 mediaItem by default. According to the Google Photos API it's possible to move that number up to 100 by setting the "pageSize" parameter. However when using the Java client we cannot find how to correctly set this parameter.

There is a libraryResponse.iterateFixedSizeCollections(collectionSize); but looking at the method's doc it says:

it is an error to call this method if the optional parameter 'page_size' has not been * set in the original API call. It is also an error if the collectionSize parameter is less than * the page_size.

What is the "original API call"? What are the steps required in order to set pageSize correctly?

标签: javaandroidgoogle-photos-api

解决方案


推荐阅读