Abos auflisten (v1)

Alle Analytics Hub-Abos in einem Projekt und an einem Standort auflisten.

Codebeispiel

Node.js

Bevor Sie dieses Beispiel anwenden, folgen Sie den Schritten zur Einrichtung von Node.js in der BigQuery-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Angaben finden Sie in der Referenzdokumentation zur BigQuery Node.js API.

Richten Sie zur Authentifizierung bei BigQuery die Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für Clientbibliotheken einrichten.

'use strict';

const {AnalyticsHubServiceClient} = require('@google-cloud/bigquery-analyticshub');
const {status} = require('@grpc/grpc-js');

const client = new AnalyticsHubServiceClient();

/**
 * Lists subscriptions in a Google Cloud project and location.
 */
async function listSubscriptions() {
  try {
    const projectId = await client.getProjectId();
    const location = 'us';
    const parent = client.locationPath(projectId, location);

    const request = {
      parent,
    };

    const [subscriptions] = await client.listSubscriptions(request);
    console.log(`Retrieved ${subscriptions.length} subscription(s).`);
    for (const subscription of subscriptions) {
      console.log(`Subscription: ${subscription.name}`);
      console.log(`State: ${subscription.state}`);
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Resource not found: ${err.message}`);
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error(`Permission denied: ${err.message}`);
    } else if (err.code === status.INVALID_ARGUMENT) {
      console.error(`Invalid argument: ${err.message}`);
    } else {
      console.error(`API error: ${err.message}`);
    }
  }
}

module.exports = { listSubscriptions };

Nächste Schritte

Wenn Sie nach Codebeispielen für andere Produkte von Google Cloud suchen und filtern möchten, können Sie den Beispielbrowser fürGoogle Cloud verwenden.