Utilizzare gli account di servizio OAuth 2.0 con l'API Manufacturer Center

Gli account di servizio sono Account Google speciali che possono essere utilizzati dalle applicazioni per accedere alle API di Google in modo programmatico mediante OAuth 2.0. Un account di servizio utilizza un flusso OAuth 2.0 che non richiede autorizzazioni aggiuntive. Utilizza invece un file chiave accessibile soltanto dall'applicazione. Questa guida illustra come accedere all'API Manufacturer Center con gli account di servizio.

Prerequisiti

Passaggi per accedere a un account di servizio per accedere all'API Manufacturer Center

  1. Genera le credenziali dell'account di servizio o accedi alle credenziali pubbliche che hai già generato. Dovrai creare un ID client OAuth 2.0 e ottenere un file della chiave privata *.json:

    1. Vai alla console dell'API di Google.

    2. Seleziona un progetto nel menu a discesa nella parte superiore della pagina. Se non ne hai ancora uno, fai clic su Crea progetto per crearne uno.

    3. Se non hai ancora abilitato l'API Manufacturer Center per questo progetto, cercala nell'elenco delle API di Google e abilitala.

    4. Nella barra laterale a sinistra, seleziona Credenziali.

    5. Per configurare un account di servizio, seleziona Crea credenziali, quindi Chiave account di servizio. ![Crea le credenziali dell'account di servizio

screenshot.](../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

screenshot.](../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. Aggiungi il nuovo account di servizio come utente al tuo account Manufacturer Center. Se sei uno sviluppatore di terze parti, dovrai chiedere al cliente di farlo per te.

    1. Vai al tuo account Manufacturer Center.

    2. Vai all'elenco "Utenti" nelle impostazioni del tuo account Manufacturer Center.

    3. Fai clic sul pulsante +Utente e utilizza l'ID account di servizio come indirizzo email del nuovo utente. ![Aggiungi pulsante utente account di servizio

screenshot.](../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

screenshot.](../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. Ora puoi accedere al tuo account Manufacturer Center utilizzando l'account di servizio utilizzando direttamente il flusso Credenziali predefinite dell'applicazione Google o il flusso dell'account di servizio. Gli esempi dell'API Manufacturer Center mostrano come utilizzare entrambi i flussi per le credenziali dell'account di servizio in ogni linguaggio di programmazione supportato. Guarda gli esempi di codice per provare il nuovo account di servizio e scoprire quali modifiche saranno necessarie per utilizzare gli account di servizio nel tuo codice.

Domande frequenti

Posso accedere all'interfaccia utente web di Manufacturer Center con il mio account di servizio?

No, gli account di servizio non sono normali Account Google e non possono accedere all'interfaccia utente web di Manufacturer Center.

Con quale frequenza devo aggiornare i token di accesso dell'account di servizio?

I token di accesso scadono un'ora dopo l'emissione dal server di autorizzazione Google OAuth 2.0. Alla scadenza di un token di accesso, l'applicazione deve utilizzare la libreria client per recuperare un altro token di accesso.