Cloud Functions 用戶端程式庫

本頁面說明如何開始使用 Cloud Functions API 適用的 Cloud 用戶端程式庫。用戶端程式庫可讓您更輕鬆地透過支援的語言存取Google Cloud API。雖然您可以直接向伺服器發出原始要求來使用Google Cloud API,但用戶端程式庫提供簡化功能,可大幅減少您需要編寫的程式碼數量。

如要進一步瞭解 Cloud 用戶端程式庫和舊版 Google API 用戶端程式庫,請參閱用戶端程式庫說明

安裝用戶端程式庫

C#

Install-Package Google.Cloud.Functions.V1 -Pre

詳情請參閱「設定 C# 開發環境」。

Go

go get -d cloud.google.com/go/...

詳情請參閱「設定 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.

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>libraries-bom</artifactId>
      <version>26.61.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-functions</artifactId>
  </dependency>
</dependencies>

If you are using Gradle, add the following to your dependencies:

implementation 'com.google.cloud:google-cloud-functions:2.65.0'

If you are using sbt, add the following to your dependencies:

libraryDependencies += "com.google.cloud" % "google-cloud-functions" % "2.65.0"

詳情請參閱「設定 Java 開發環境」一文。

Node.js

npm install @google-cloud/functions

詳情請參閱「設定 Node.js 開發環境」一文。

PHP

composer require google/cloud

詳情請參閱「在 Google Cloud 上使用 PHP」。

Python

pip install --upgrade google-api-python-client

詳情請參閱「設定 Python 開發環境」一文。

Ruby

gem install google-cloud-functions

詳情請參閱「設定 Ruby 開發環境」一文。

設定驗證方法

為了驗證對 Google Cloud API 的呼叫,用戶端程式庫支援應用程式預設憑證 (ADC);這些程式庫會在一系列定義的位置尋找憑證,然後使用這些憑證驗證對 API 的要求。有了 ADC,您就能在各種環境 (例如本機開發或正式版) 中為應用程式提供憑證,而無需修改應用程式程式碼。

在實際工作環境中,您設定 ADC 的方式取決於服務和情境。詳情請參閱「設定應用程式預設憑證」。

如果是本機開發環境,您可以使用與 Google 帳戶相關聯的憑證設定 ADC:

  1. After installing the Google Cloud CLI, initialize it by running the following command:

    gcloud init

    If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  2. 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 使用的本機憑證檔案中。

其他資源

C#

以下清單包含與 C# 用戶端程式庫相關的更多資源連結:

Go

以下清單包含與 Go 用戶端程式庫相關的更多資源連結:

Java

下列清單包含適用於 Java 用戶端程式庫的更多資源連結:

Node.js

以下清單列出與 Node.js 用戶端程式庫相關的更多資源連結:

PHP

下列清單包含與 PHP 用戶端程式庫相關的更多資源連結:

Python

以下清單包含與 Python 用戶端程式庫相關的更多資源連結:

Ruby

以下清單包含與 Ruby 用戶端程式庫相關的更多資源連結: