在AWS PHP SDK v3中分页列出Cognito身份

时间:2017-09-09 14:28:20

标签: php amazon-web-services aws-sdk aws-cognito aws-php-sdk

如何使用AWS PHP SDK v3对结果进行分页时获取所有记录?我有以下代码:

override func layoutSubviews() {
    super.layoutSubviews()
    for subview in self.subviews {
        if String(describing: type(of: subview.self)) == "UITableViewCellDeleteConfirmationView" {
            let deleteButton = subview
            let deleteButtonFrame = deleteButton.frame
            let newFrame = CGRect(x: deleteButtonFrame.minX, 
                                  y: deleteButtonFrame.minY,
                                  width: deleteButtonFrame.width,
                                  height: yourHeight)
            deleteButton.frame = newFrame
        }
    }
}

看起来应该有效,但会产生错误:

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:****************************',
]);

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 方法存在,但文件getPaginator为空,因此未实现任何分页器。我在回复中看到了data/cognito-identity/2014-06-30/paginators-1.json.php,但是无法理解无缝加载更多结果的模式(NextToken?)

1 个答案:

答案 0 :(得分:0)

我解决了这个问题:

$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'));
}