Datenquelle abrufen

Ruft Informationen für eine bestimmte Datenquelle ab, z. B. Google Ads oder YouTube, die vom BigQuery Data Transfer Service unterstützt wird.

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.

const {DataTransferServiceClient} =
  require('@google-cloud/bigquery-data-transfer').v1;
const {status} = require('@grpc/grpc-js');

const client = new DataTransferServiceClient();

/**
 * Retrieves a supported data source and returns its settings.
 * This sample shows how to get a data source's details, to understand its parameters and capabilities before creating a transfer.
 *
 * @param {string} projectId The project ID to use, for example 'example-project-id'
 * @param {string} location The location to use, for example 'us-central1'
 * @param {string} dataSourceId The data source ID to use, for example 'google_cloud_storage'
 */
async function getDataSource(projectId, location, dataSourceId) {
  const name = client.projectLocationDataSourcePath(
    projectId,
    location,
    dataSourceId,
  );

  const request = {
    name,
  };

  try {
    const [dataSource] = await client.getDataSource(request);
    console.log(`Data source ${dataSource.name} retrieved:`);
    console.log(`  Display Name: ${dataSource.displayName}`);
    console.log(`  Description: ${dataSource.description}`);
    console.log(`  Data Source ID: ${dataSource.dataSourceId}`);
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(
        `Data source ${dataSourceId} not found in project ${projectId} in location ${location}.`,
      );
    } else {
      console.error(`Error getting data source ${dataSourceId}:`, err);
    }
  }
}

Python

Bevor Sie dieses Beispiel ausprobieren, folgen Sie der Python-Einrichtungsanleitung in der BigQuery-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Angaben finden Sie in der Referenzdokumentation zur BigQuery Python API.

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

import google.api_core.exceptions
from google.cloud import bigquery_datatransfer_v1

client = bigquery_datatransfer_v1.DataTransferServiceClient()


def get_data_source(project_id: str, data_source_id: str) -> None:
    """Retrieves a data source definition by name.

    This sample shows how to get a data source definition, which includes its
    display name, description, and other properties.

    Args:
        project_id: The Google Cloud project ID.
        data_source_id: The data source ID, for example, 'google_cloud_storage'.
    """
    name = client.data_source_path(project=project_id, data_source=data_source_id)

    try:
        response = client.get_data_source(name=name)
        print(f"Retrieved data source: {response.name}")
        print(f"Display Name: {response.display_name}")
        print(f"Description: {response.description}")
        print(f"Client ID: {response.client_id}")
        print(f"Supports custom schedule: {response.supports_custom_schedule}")
    except google.api_core.exceptions.NotFound:
        print(f"Error: Data source '{name}' was not found.")

Weitere Informationen

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.