This page shows how to get started with the Cloud Client Libraries for the BigQuery Connection API. Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.
Installing the client library
Go
For more information, see Setting Up a Go Development Environment.
go get -u cloud.google.com/go/bigquery
Java
For more information, see Setting Up a Java Development Environment.
Wenn Sie Maven verwenden, fügen Sie Ihrer Datei pom.xml
den folgenden Code hinzu. Weitere Informationen zu BOMs finden Sie unter The Google Cloud Platform Libraries BOM.
Wenn Sie Gradle verwenden, fügen Sie den Abhängigkeiten Folgendes hinzu:
Wenn Sie sbt nutzen, fügen Sie den Abhängigkeiten Folgendes hinzu:
Bei Verwendung von IntelliJ oder Eclipse können Sie Ihrem Projekt mithilfe der folgenden IDE-Plug-ins Clientbibliotheken hinzufügen:
Diese Plug-ins bieten zusätzliche Funktionen wie die Schlüsselverwaltung für Dienstkonten. Einzelheiten finden Sie in der Dokumentation der einzelnen Plug-ins.
Python
For more information, see Setting Up a Python Development Environment.
pip install --upgrade google-cloud-bigquery-connection
Setting up authentication
To run the client library, you must first set up authentication by creating a service account and setting an environment variable. Complete the following steps to set up authentication. For other ways to authenticate, see the GCP authentication documentation.
Cloud Console
-
Wechseln Sie in der Cloud Console zur Seite Dienstkontoschlüssel erstellen.
Zur Seite „Dienstkontoschlüssel erstellen“ - Wählen Sie aus der Liste Dienstkonto die Option Neues Dienstkonto aus.
- Geben Sie im Feld Dienstkontoname einen Namen ein.
Wählen Sie in der Liste Rolle die Option Projekt > Inhaber
- Klicken Sie auf Erstellen. Eine JSON-Datei mit Ihrem Schlüssel wird auf Ihren Computer heruntergeladen.
Befehlszeile
Sie können die folgenden Befehle mithilfe des Cloud SDK auf Ihrem lokalen Computer oder in Cloud Shell ausführen.
-
Erstellen Sie das Dienstkonto. Ersetzen Sie NAME mit einem Namen für das Dienstkonto.
gcloud iam service-accounts create NAME
-
Gewähren Sie dem Dienstkonto Berechtigungen. Geben Sie für PROJECT_ID Ihre Projekt-ID an.
gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:NAME@PROJECT_ID.iam.gserviceaccount.com" --role="roles/owner"
-
Erstellen Sie die Schlüsseldatei. Geben Sie für FILE_NAME einen Namen für die Schlüsseldatei an.
gcloud iam service-accounts keys create FILE_NAME.json --iam-account=NAME@PROJECT_ID.iam.gserviceaccount.com
Die Anmeldedaten zur Authentifizierung für Ihren Anwendungscode geben Sie durch Festlegung der Umgebungsvariable GOOGLE_APPLICATION_CREDENTIALS
an.
Geben Sie für [PATH] den Dateipfad der JSON-Datei an, die Ihren Dienstkontoschlüssel enthält. Diese Variable gilt nur für Ihre aktuelle Shell-Sitzung. Wenn Sie eine neue Sitzung öffnen, müssen Sie die Variable neu festlegen.
Linux oder macOS
export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
Beispiel:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/my-key.json"
Windows
Mit PowerShell:
$env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
Beispiel:
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\my-key.json"
Mit Eingabeaufforderung:
set GOOGLE_APPLICATION_CREDENTIALS=[PATH]
Using the client library
The following example demonstrates some basic interactions with the BigQuery Connection API.
Go
To use this sample, prepare your machine for Go development, and complete the BigQuery Connection API quickstart. For more information, see the BigQuery Connection API Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in Setting Up a Java Development Environment. For more information, see the BigQuery Connection API Java API reference documentation.
Additional resources
Go
Java
Python
What's next?
For more background, see Working with connections.