Membuat daftar listingan (v1)

Mencantumkan semua listingan dalam pertukaran data BigQuery Analytics Hub.

Contoh kode

Python

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Python di Panduan memulai BigQuery menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi BigQuery Python API.

Untuk melakukan autentikasi ke BigQuery, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk library klien.

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}")

Langkah berikutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat browser contohGoogle Cloud .