このページでは、Google Cloud プロジェクトの設定方法と、プロジェクトにアクセスするためのサービス アカウントの構成方法について説明します。
Google Cloud プロジェクトの設定
次の手順に沿って、Google Cloud プロジェクトを設定します。CDN を使用してコンテンツを配信する予定がない場合は、(動画スティッチャー管理者のロールではなく)動画スティッチャー ユーザーのロールのみをサービス アカウントに付与する必要があります。
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
Google Cloud Console の [プロジェクト セレクタ] ページで、Google Cloud プロジェクトを選択または作成します。
-
Video Stitcher API を有効にします。
-
Create a service account:
-
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart
. - Click Create and continue.
-
Grant the Video Stitcher Admin role to the service account.
To grant the role, find the Select a role list, then select Video Stitcher Admin.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
環境変数
GOOGLE_APPLICATION_CREDENTIALS
を、認証情報を含む JSON ファイルのパスに設定します。この変数は現在のシェル セッションにのみ適用されるため、新しいセッションを開く場合は、変数を再度設定する必要があります。 -
Google Cloud Console の [プロジェクト セレクタ] ページで、Google Cloud プロジェクトを選択または作成します。
-
Video Stitcher API を有効にします。
-
Create a service account:
-
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart
. - Click Create and continue.
-
Grant the Video Stitcher Admin role to the service account.
To grant the role, find the Select a role list, then select Video Stitcher Admin.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
環境変数
GOOGLE_APPLICATION_CREDENTIALS
を、認証情報を含む JSON ファイルのパスに設定します。この変数は現在のシェル セッションにのみ適用されるため、新しいセッションを開く場合は、変数を再度設定する必要があります。 - Google Cloud CLI をインストールします。
-
gcloud CLI を初期化するには:
gcloud init
gcloud
ツールを使用して認証環境をテストします。次のコマンドが、エラーなしでテキスト文字列を出力することを確認します。gcloud auth application-default print-access-token
サービス アカウントを有効にする
- ターミナルで、gcloud コマンドが有効なプロジェクトを設定します。YOUR_PROJECT_ID は実際のプロジェクト ID で置き換えます。
gcloud config set project YOUR_PROJECT_ID
- サービス アカウントを有効にします。PATH_TO_YOUR_SERVICE_KEY は、ローカルマシンにダウンロードした JSON ファイルのパスに置き換えます。
gcloud auth activate-service-account --key-file PATH_TO_YOUR_SERVICE_KEY
このサービス アカウントを使用してアクセスを承認し、動画スティッチャー API を呼び出します。
セッションの作成権限のみを持つサービス アカウントを作成する
OAuth トークンはクライアント アプリケーションに渡されるため、セッションを作成する権限のみを持つサービス アカウントを個別に作成します。これにより、OAuth トークンが漏洩しても、リソース(CDN 鍵など)が不正にアクセスされることはなくなります。
Create a service account:
-
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart
. - Click Create and continue.
-
Grant the Video Stitcher User role to the service account.
To grant the role, find the Select a role list, then select Video Stitcher User.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.