Paging in list resource
Paging
If there are more items than the page limit, we will need to use paging. It’s possible through the nextPageToken
from the response. If it’s a string, we can use paging but if it’s false, then there are no more pages.
SDK Example
In this example we simply page through a cloud and print the uploaded image IDs.
use shardimage\shardimagephp\auth\Client;
use shardimage\shardimagephp\models\image\Image;
$client = new Client([
'apiKey' => '<apiKey>',
'apiSecret' => '<apiSecret>',
'imageSecret' => '<imageSecret>',
]);
$client->cloudId = '<cloudId>';
$nextPageToken = false;
$optParams = [
'maxResults' => 100,
];
do {
$result = $client->getImageService()->index($client->cloudId, $optParams);
$models = $result->models;
foreach ($models as $model) {
if ($model instanceof Image) {
echo "$model->publicId\n";
} else {
// handle error
}
}
$nextPageToken = $result->nextPageToken;
if ($nextPageToken !== false) {
echo "////////////////////NEXT PAGE////////////////////\n";
$optParams['pageToken'] = $nextPageToken;
}
} while ($nextPageToken !== false);