列出共用資源訂閱項目 (v1)

列出資料交換作業的所有共用資源訂閱項目。

程式碼範例

Java

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

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

import com.google.cloud.bigquery.analyticshub.v1.AnalyticsHubServiceClient;
import com.google.cloud.bigquery.analyticshub.v1.DataExchangeName;
import com.google.cloud.bigquery.analyticshub.v1.ListSharedResourceSubscriptionsRequest;
import com.google.cloud.bigquery.analyticshub.v1.Subscription;
import java.io.IOException;

public class ListSharedResourceSubscriptions {

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

  public static void listSharedResourceSubscriptions(
      String projectId, String locationId, String dataExchangeId) throws IOException {
    // Initialize the client. Create once and reuse across requests.
    try (AnalyticsHubServiceClient client = AnalyticsHubServiceClient.create()) {
      String resource = DataExchangeName.of(projectId, locationId, dataExchangeId).toString();

      ListSharedResourceSubscriptionsRequest request =
          ListSharedResourceSubscriptionsRequest.newBuilder()
              .setResource(resource)
              .build();

      for (Subscription subscription : client.listSharedResourceSubscriptions(request).iterateAll()) {
        System.out.println("Shared resource subscription: " + subscription.getName());
      }
    }
  }
}

後續步驟

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