Manufacturer Center API での OAuth 2.0 サービス アカウントの使用

サービス アカウントは特別な Google アカウントで、アプリケーションが OAuth 2.0 を介して Google API にプログラムでアクセスできます。サービス アカウントは、追加の承認を必要としない OAuth 2.0 フローを使用します。アプリケーションのみがアクセスできるキーファイルが使用されます。このガイドでは、サービス アカウントを使用して Manufacturer Center API にアクセスする方法について説明します。

Prerequisites

サービス アカウントを使用して Manufacturer Center API にアクセスする手順

  1. サービス アカウントの認証情報を生成するか、生成済みの公開認証情報にアクセスします。OAuth 2.0 クライアント ID を作成して、*.json 秘密鍵ファイルを取得する必要があります。

    1. Google API Console に移動します。

    2. ページの上部にあるプルダウン メニューでプロジェクトを選択します。まだ作成していない場合は、[プロジェクトを作成] をクリックして作成します。

    3. このプロジェクトで Manufacturer Center API をまだ有効にしていない場合は、Google API のリストで検索し、Manufacturer Center API を有効にします。

    4. 左側のサイドバーで [認証情報] を選択します。

    5. サービス アカウントを設定するには、[認証情報を作成]、[サービス アカウント キー] の順に選択します。![サービス アカウントの認証情報を作成する

スクリーンショット](../images/create_service_account_credentials.png)

6.  On the next page, select **New service account** from the drop-down
    list.

7.  <a name="service-account-name"></a> Name the new service account. This
    also serves as the default username for the service account ID. Remember
the service account ID for use later.

Note: The choice of role for the service account will not have any effect on
what calls can be made to the Manufacturer Center API, as access to
    Manufacturer Center API methods is determined instead by the role
    associated with the service account ID in Manufacturer Center. If you
    are unsure what to pick, just pick Project►Viewer.

![New service account name

スクリーンショット](../images/new_service_account_name.png)

8.  Select **JSON** for the key type, then click **Create**.

9.  The **Create** button will change to **Creating...**, and once the key
    generation finishes, it will automatically download the private key as a
*.json file.

Important: Protect the *.json key file that allows a service account to
    access the Google services for which it has been authorized. It is good
practice to allow service accounts to only access one Google API each. This
is a preventative measure to mitigate the amount of data an attacker can
    access in the situation that the service account's *.json key file is
    compromised.

10.  You will be returned to the Credentials page, and you should see the
    new service account in the list of service account keys for your
    account.
  1. 新しいサービス アカウントを Manufacturer Center アカウントにユーザーとして追加します。 サードパーティのデベロッパーの場合は、クライアントでこの手順を実施する必要があります。

    1. Manufacturer Center アカウントにアクセスします。

    2. Manufacturer Center アカウントの設定の [ユーザー] リストに移動します。

    3. [+ ユーザー] ボタンをクリックし、新しいサービス アカウントのメールアドレスとしてサービス アカウント ID を使用します。![サービス アカウント ユーザーの追加] ボタン

スクリーンショット](../images/add_service_account_network_settings.png)

4.  Fill in the form with the [service account ID](#service-account-name),
    and select the desired user role(s). At least one must be chosen, and
    use of the `Accounts` service requires the Admin role.

If you did not take note of the service account ID earlier, go to the
    [Service
    Accounts](https://console.developers.google.com/iam-admin/serviceaccounts/)
administration page and select the project you created.

![Add service account user page

スクリーンショット](../images/add_service_account_page.png)

5.  Click on the **Save** button. You will be returned to the list of users,
and the service account ID should be listed with the chosen user role(s).

6.  Repeat the process for all other service accounts you want to add.

7.  View existing service account users by going to the Users tab. These
    will be users with an email address ending in 'gserviceaccount.com'.
  1. これで、Google アプリケーションのデフォルト認証情報フローまたはサービス アカウント フローを直接使用すると、サービス アカウントを使用して Manufacturer Center アカウントにアクセスできるようになります。Manufacturer Center API のサンプルでは、サポートされている各プログラミング言語でサービス アカウントの認証情報に対して両方のフローを使用する方法を示しています。コードサンプルを確認して新しいサービス アカウントを試し、独自のコードでサービス アカウントを使用するために必要な変更を確認してください。

よくある質問

サービス アカウントで Manufacturer Center のウェブ ユーザー インターフェースにログインできますか?

いいえ。サービス アカウントは通常の Google アカウントではなく、Manufacturer Center のウェブ ユーザー インターフェースにアクセスできません。

サービス アカウントのアクセス トークンはどのくらいの頻度で更新する必要がありますか?

アクセス トークンは、Google OAuth 2.0 認可サーバーによって発行されてから 1 時間後に期限切れになります。アクセス トークンが期限切れになった場合、アプリケーションはクライアント ライブラリを使用して別のアクセス トークンを取得する必要があります。