使用 API 金鑰存取 API

本頁說明如何使用 API 金鑰存取接受 API 金鑰的 Trusted Cloud by S3NS API 和服務。

並非所有 Trusted Cloud by S3NS API 都接受 API 金鑰授權使用。請參閱要使用的服務或 API 說明文件,確認是否接受 API 金鑰。

如要瞭解如何建立及管理 API 金鑰 (包括限制 API 金鑰),請參閱「管理 API 金鑰」一文。

事前準備

Select the tab for how you plan to use the samples on this page:

C#

如要在本機開發環境中使用本頁的 .NET 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。

  1. Install the Google Cloud CLI.

  2. Configure the gcloud CLI to use your federated identity.

    For more information, see Sign in to the gcloud CLI with your federated identity.

  3. Create local authentication credentials for your user account:

    gcloud auth application-default login

    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.

詳情請參閱 Trusted Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。

C++

如要在本機開發環境中使用本頁的 C++ 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。

  1. Install the Google Cloud CLI.

  2. Configure the gcloud CLI to use your federated identity.

    For more information, see Sign in to the gcloud CLI with your federated identity.

  3. Create local authentication credentials for your user account:

    gcloud auth application-default login

    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.

詳情請參閱 Trusted Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。

Go

如要在本機開發環境中使用本頁的 Go 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。

  1. Install the Google Cloud CLI.

  2. Configure the gcloud CLI to use your federated identity.

    For more information, see Sign in to the gcloud CLI with your federated identity.

  3. Create local authentication credentials for your user account:

    gcloud auth application-default login

    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.

詳情請參閱 Trusted Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。

Node.js

如要在本機開發環境中使用本頁的 Node.js 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。

  1. Install the Google Cloud CLI.

  2. Configure the gcloud CLI to use your federated identity.

    For more information, see Sign in to the gcloud CLI with your federated identity.

  3. Create local authentication credentials for your user account:

    gcloud auth application-default login

    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.

詳情請參閱 Trusted Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。

Python

如要在本機開發環境中使用本頁的 Python 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。

  1. Install the Google Cloud CLI.

  2. Configure the gcloud CLI to use your federated identity.

    For more information, see Sign in to the gcloud CLI with your federated identity.

  3. Create local authentication credentials for your user account:

    gcloud auth application-default login

    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.

詳情請參閱 Trusted Cloud 驗證說明文件中的「 為本機開發環境設定 ADC」。

REST

如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。

    Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity.

詳情請參閱 Trusted Cloud 驗證說明文件中的「Authenticate for using REST」。

搭配 REST 使用 API 金鑰

如要在 REST API 呼叫中加入 API 金鑰,請使用 x-goog-api-key HTML 標頭。

如果無法使用 HTTP 標頭,可以改用 key 查詢參數。不過,這個方法會在網址中加入 API 金鑰,導致金鑰暴露於網址掃描。

搭配用戶端程式庫使用 API 金鑰

在應用程式中使用 API 金鑰時,請確保儲存和傳輸期間的金鑰安全無虞。公開 API 金鑰可能會導致帳戶產生非預期費用。詳情請參閱「管理 API 金鑰的最佳做法」。

後續步驟