[英]Paginating List Cognito Identities in AWS PHP SDK v3
How do I fetch all records when the result is paginated, using the AWS PHP SDK v3? 在使用AWS PHP SDK v3对结果进行分页时,如何获取所有记录? I have the following code:
我有以下代码:
require_once 'vendor/autoload.php';
$cognitoIdentityClient = new Aws\CognitoIdentity\CognitoIdentityClient([
'region' => 'eu-west-1',
'version' => '2014-06-30',
'credentials' => [
'key' => '**************',
'secret' => '***************',
],
]);
$identities = $cognitoIdentityClient->getPaginator('ListIdentities', [
'IdentityPoolId' => 'eu-west-1:****************************',
]);
which looks like it should work, but produces the error: 看起来应该可以工作,但是会产生错误:
Fatal error: Uncaught UnexpectedValueException: There is no ListIdentities paginator defined for the cognito-identity service. in /path/to/vendor/aws/aws-sdk-php/src/Api/Service.php:363
Stack trace:
#0 /path/to/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(23): Aws\Api\Service->getPaginatorConfig('ListIdentities')
#1 /path/to/report.php(24): Aws\AwsClient->getIterator('ListIdentities', Array)
#2 {main}
thrown in /path/to/vendor/aws/aws-sdk-php/src/Api/Service.php on line 363
The getPaginator
method exists, but the file data/cognito-identity/2014-06-30/paginators-1.json.php
is blank, so no paginators are implemented. getPaginator
方法存在,但文件data/cognito-identity/2014-06-30/paginators-1.json.php
为空,因此未实现任何分页器。 I see NextToken
in the response, but don't understand the pattern to seamlessly load more results ( do (...) {} while (...)
?) 我在响应中看到
NextToken
,但不了解无缝加载更多结果的模式( do (...) {} while (...)
吗?)
I solved it like this: 我这样解决了:
$identities = [];
$i = $cognitoIdentityClient->listIdentities([
'IdentityPoolId' => IDENTITYPOOLID,
'MaxResults' => 60,
]);
$identities = array_merge($identities, $i->get('Identities'));
while ($nextToken = $i->get('NextToken')) {
$i = $cognitoIdentityClient->listIdentities([
'IdentityPoolId' => IDENTITYPOOLID,
'MaxResults' => 60,
'NextToken' => $nextToken,
]);
$identities = array_merge($identities, $i->get('Identities'));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.