ページネーションを管理する

Google Cloud Java ライブラリのほとんどのリスト メソッドは、PagedResponse オブジェクトを返します。これにより、ページトークンを手動で管理することなく、結果を反復処理できます。

ページネーションを処理する最も簡単な方法は、iterateAll() メソッドを使用することです。ライブラリは、コレクションを反復処理する際に、バックグラウンドで新しいページを自動的に取得します。

import com.google.cloud.secretmanager.v1.ListSecretsRequest;
import com.google.cloud.secretmanager.v1.ProjectName;
import com.google.cloud.secretmanager.v1.Secret;
import com.google.cloud.secretmanager.v1.SecretManagerServiceClient;

try (SecretManagerServiceClient secretManager = SecretManagerServiceClient.create()) {
    // Prepare the request
    ListSecretsRequest request = ListSecretsRequest.newBuilder()
        .setParent(ProjectName.of("my-project").toString())
        .build();

    // Call the API