始める前に

このページでは、Google Cloud プロジェクトの設定方法と、プロジェクトにアクセスするためのサービス アカウントの構成方法について説明します。

Google Cloud プロジェクトの設定

次の手順に沿って、Google Cloud プロジェクトを設定します。CDN を使用してコンテンツを配信する予定がない場合は、(動画スティッチャー管理者のロールではなく)動画スティッチャー ユーザーのロールのみをサービス アカウントに付与する必要があります。

  1. 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.
  2. Google Cloud Console の [プロジェクト セレクタ] ページで、Google Cloud プロジェクトを選択または作成します。

    プロジェクト セレクタに移動

  3. Google Cloud プロジェクトで課金が有効になっていることを確認します

  4. Video Stitcher API を有効にします。

    API を有効にする

  5. Create a service account:

    1. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    2. Select your project.
    3. 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.

    4. Click Create and continue.
    5. 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.

    6. Click Continue.
    7. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  6. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, and then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  7. 環境変数 GOOGLE_APPLICATION_CREDENTIALS を、認証情報を含む JSON ファイルのパスに設定します。この変数は現在のシェル セッションにのみ適用されるため、新しいセッションを開く場合は、変数を再度設定する必要があります。

  8. Google Cloud Console の [プロジェクト セレクタ] ページで、Google Cloud プロジェクトを選択または作成します。

    プロジェクト セレクタに移動

  9. Google Cloud プロジェクトで課金が有効になっていることを確認します

  10. Video Stitcher API を有効にします。

    API を有効にする

  11. Create a service account:

    1. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    2. Select your project.
    3. 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.

    4. Click Create and continue.
    5. 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.

    6. Click Continue.
    7. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  12. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, and then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  13. 環境変数 GOOGLE_APPLICATION_CREDENTIALS を、認証情報を含む JSON ファイルのパスに設定します。この変数は現在のシェル セッションにのみ適用されるため、新しいセッションを開く場合は、変数を再度設定する必要があります。

  14. Google Cloud CLI をインストールします。
  15. gcloud CLI を初期化するには:

    gcloud init
  16. gcloud ツールを使用して認証環境をテストします。次のコマンドが、エラーなしでテキスト文字列を出力することを確認します。
    gcloud auth application-default print-access-token

サービス アカウントを有効にする

  1. ターミナルで、gcloud コマンドが有効なプロジェクトを設定します。YOUR_PROJECT_ID は実際のプロジェクト ID で置き換えます。
    gcloud config set project YOUR_PROJECT_ID
    
  2. サービス アカウントを有効にします。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:

  1. In the Google Cloud console, go to the Create service account page.

    Go to Create service account
  2. Select your project.
  3. 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.

  4. Click Create and continue.
  5. 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.

  6. Click Continue.
  7. 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:

  1. In the Google Cloud console, click the email address for the service account that you created.
  2. Click Keys.
  3. Click Add key, and then click Create new key.
  4. Click Create. A JSON key file is downloaded to your computer.
  5. Click Close.