更新商店資訊 (v1)

更新資料交換中現有產品資訊的說明。

程式碼範例

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 BigQuery 快速入門導覽課程」中的 Java 設定操作說明進行操作。詳情請參閱 BigQuery Java API 參考文件。

如要向 BigQuery 進行驗證,請設定應用程式預設憑證。詳情請參閱「設定用戶端程式庫的驗證機制」。

import com.google.cloud.bigquery.analyticshub.v1.AnalyticsHubServiceClient;
import com.google.cloud.bigquery.analyticshub.v1.Listing;
import com.google.protobuf.FieldMask;
import java.io.IOException;

public class UpdateListing {

  public static void main(String[] args) throws IOException {
    String projectId = "example-project-id";
    String locationId = "example-location-id";
    String dataExchangeId = "example-data-exchange-id";
    String listingId = "example-listing-id";
    updateListing(projectId, locationId, dataExchangeId, listingId);
  }

  public static void updateListing(
      String projectId, String locationId, String dataExchangeId, String listingId)
      throws IOException {
    try (AnalyticsHubServiceClient client = AnalyticsHubServiceClient.create()) {
      String listingName =
          String.format(
              "projects/%s/locations/%s/dataExchanges/%s/listings/%s",
              projectId, locationId, dataExchangeId, listingId);
      Listing listing =
          Listing.newBuilder()
              .setName(listingName)
              .setDescription("Updated description for the listing")
              .build();
      FieldMask updateMask = FieldMask.newBuilder().addPaths("description").build();

      Listing response = client.updateListing(listing, updateMask);
      System.out.println("Listing updated successfully: " + response.getName());
    }
  }
}

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 BigQuery 快速入門導覽課程」中的 Python 設定操作說明進行操作。詳情請參閱 BigQuery Python API 參考文件。

如要向 BigQuery 進行驗證,請設定應用程式預設憑證。詳情請參閱「設定用戶端程式庫的驗證機制」。

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


def update_listing(
    project_id: str,
    location_id: str,
    data_exchange_id: str,
    listing_id: str,
) -> None:
    """Updates an Analytics Hub listing.

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

    listing_name = (
        f"projects/{project_id}/locations/{location_id}/"
        f"dataExchanges/{data_exchange_id}/listings/{listing_id}"
    )

    listing = bigquery_analyticshub_v1.Listing(
        name=listing_name,
        description="Updated description for the listing.",
    )
    update_mask = field_mask_pb2.FieldMask(paths=["description"])

    request = bigquery_analyticshub_v1.UpdateListingRequest(
        listing=listing,
        update_mask=update_mask,
    )

    try:
        response = client.update_listing(request=request)
        print(f"Updated listing: {response.name}")
        print(f"Description: {response.description}")
    except exceptions.GoogleAPICallError as error:
        print(f"API call failed: {error}")

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱Google Cloud 範例瀏覽工具。