本頁說明如何開始使用 BigQuery API 適用的 Cloud 用戶端程式庫。有了用戶端程式庫,您可以透過支援的語言,更輕鬆地存取Google Cloud API。雖然您可以直接向伺服器發出原始要求來使用Google Cloud API,但用戶端程式庫提供簡化功能,可大幅減少需要編寫的程式碼數量。
如要進一步瞭解 Cloud 用戶端程式庫和舊版 Google API 用戶端程式庫,請參閱「用戶端程式庫說明」。
安裝用戶端程式庫
C#
Install-Package Google.Cloud.BigQuery.V2 -Pre
詳情請參閱「設定 C# 開發環境」。
Go
go get cloud.google.com/go/bigquery
詳情請參閱「設定 Go 開發環境」。
Java
If you are using Maven, add
the following to your pom.xml file. For more information about
BOMs, see The Google Cloud Platform Libraries BOM.
If you are using Gradle, add the following to your dependencies:
If you are using sbt, add the following to your dependencies:
If you're using Visual Studio Code or IntelliJ, you can add client libraries to your project using the following IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
詳情請參閱「設定 Java 開發環境」。
Node.js
npm install @google-cloud/bigquery
詳情請參閱「設定 Node.js 開發環境」。
PHP
composer require google/cloud-bigquery
詳情請參閱「在 Google Cloud 上使用 PHP」。
Python
pip install --upgrade google-cloud-bigquery
詳情請參閱「設定 Python 開發環境」。
Ruby
gem install google-cloud-bigquery
詳情請參閱「設定 Ruby 開發環境」。
設定驗證方法
為驗證向 Google Cloud API 發出的呼叫,用戶端程式庫支援應用程式預設憑證 (ADC);程式庫會在定義的一組位置中尋找憑證,並使用這些憑證驗證向 API 發出的要求。有了 ADC,無需修改應用程式程式碼,就能在各種環境 (例如本機開發環境或正式環境),為應用程式提供憑證。在正式環境中,設定 ADC 的方式取決於服務和背景。詳情請參閱「設定應用程式預設憑證」。
在本機開發環境中,您可以使用與 Google 帳戶相關聯的憑證設定 ADC:
-
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
登入畫面會隨即顯示。登入後,您的憑證會儲存在 ADC 使用的本機憑證檔案中。
使用用戶端程式庫
以下範例說明如何初始化用戶端,並對 BigQuery API 公開資料集執行查詢。
C#
Go
Java
Node.js
PHP
Python
Ruby
其他資源
C#
下方列出與 C# 用戶端程式庫相關的其他資源連結:
Go
下方列出與 Go 用戶端程式庫相關的其他資源連結:
Java
下方列出與 Java 用戶端程式庫相關的其他資源連結:
Node.js
下方列出與 Node.js 用戶端程式庫相關的其他資源連結:
PHP
下方列出與 PHP 用戶端程式庫相關的其他資源連結:
Python
下方列出與 Python 用戶端程式庫相關的其他資源連結:
Ruby
下方列出與 Ruby 用戶端程式庫相關的其他資源連結:
第三方 BigQuery API 用戶端程式庫
除了上表列出的 Google 支援的用戶端程式庫外,還可使用一組第三方程式庫。
| 語言 | 程式庫 |
|---|---|
| Python | pandas-gbq (使用指南)、ibis (教學課程) |
| R | bigrquery、BigQueryR |
| Scala | spark-bigquery-connector |
後續步驟
歡迎試用
如果您未曾使用過 Google Cloud,歡迎建立帳戶,親自體驗實際使用 BigQuery 的成效。新客戶還能獲得價值 $300 美元的免費抵免額,用於執行、測試及部署工作負載。
免費試用 BigQuery