リスティングを一覧表示する(v1)

BigQuery Analytics Hub データ エクスチェンジ内のすべてのリスティングを一覧表示します。

コードサンプル

Python

このサンプルを試す前に、クライアント ライブラリを使用した BigQuery クイックスタートにある Python の設定手順を完了してください。詳細については、BigQuery Python API のリファレンス ドキュメントをご覧ください。

BigQuery に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、クライアント ライブラリの認証情報を設定するをご覧ください。

from google.api_core import exceptions
from google.cloud import bigquery_analyticshub_v1


def list_listings(project_id: str, location_id: str, data_exchange_id: str) -> None:
    """Lists listings in a BigQuery Analytics Hub data exchange.

    Args:
        project_id: The Google Cloud project ID.
        location_id: The Google Cloud region or location for the data exchange (for example, 'us').
        data_exchange_id: The ID of the data exchange.
    """
    client = bigquery_analyticshub_v1.AnalyticsHubServiceClient()

    parent = (
        f"projects/{project_id}/locations/{location_id}/dataExchanges/{data_exchange_id}"
    )

    request = bigquery_analyticshub_v1.ListListingsRequest(parent=parent)

    try:
        response = client.list_listings(request=request)
        for listing in response:
            print(f"Listing name: {listing.name}")
            print(f"Display name: {listing.display_name}")
    except exceptions.GoogleAPICallError as error:
        print(f"Request failed with API error: {error}")

次のステップ

他の Google Cloud プロダクトのコードサンプルを検索およびフィルタするには、Google Cloud サンプル ブラウザをご覧ください。