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 認証ドキュメントの REST を使用して認証するをご覧ください。

REST で API キーを使用する

REST API 呼び出しに API キーを含めるには、x-goog-api-key HTML ヘッダーを使用します。

HTTP ヘッダーを使用できない場合は、key クエリ パラメータを使用できます。ただし、この方法では API キーが URL に含まれるため、URL スキャンでキーが公開されます。

クライアント ライブラリで API キーを使用する