rocket
Scopri l'
API Merchant, il successore ufficiale dell'API Content for Shopping.
add_alert
Nota: l'API Content for Shopping verrà ritirata il 18 agosto 2026.
Service account
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Gli account di servizio sono Account Google speciali che possono essere utilizzati dalle applicazioni per accedere alle API di Google in modo programmatico tramite OAuth 2.0. Un account di servizio utilizza un flusso OAuth 2.0 che non richiede l'autorizzazione di un utente.
Utilizza invece un file chiave accessibile soltanto dalla tua applicazione. Questa guida illustra come accedere all'API Content for Shopping con gli account di servizio.
Nota: le applicazioni che utilizzano account di servizio per l'autenticazione possono accedere solo al tuo account Merchant Center. Se stai scrivendo un'applicazione di terze parti che ha bisogno di accedere agli account Merchant Center dei tuoi clienti, consulta la guida sulle richieste di autorizzazione.
Prerequisiti
Procedura per utilizzare un account di servizio per accedere all'API Content for Shopping
- 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:
- Vai alla console dell'API di Google.
- Seleziona un progetto nel menu a discesa nella parte superiore della pagina. Se non ne hai ancora uno, creane uno facendo clic su NUOVO PROGETTO.
- Se non hai già abilitato l'API Content for Shopping per questo progetto, cercala nell'elenco delle API di Google e abilitala.
- Nella barra laterale a sinistra, seleziona Credenziali.
Per visualizzarla, potrebbe essere necessario fare clic sulla freccia rivolta verso sinistra in alto a sinistra.
- Per configurare un account di servizio, seleziona CREA CREDENZIALI, quindi Account di servizio.
- Assegnare un nome al nuovo account di servizio. Inoltre, funge da nome utente predefinito per l'ID account di servizio. Registra l'ID account di servizio, inclusa la parte dopo
il carattere "@", per utilizzarlo in un secondo momento. Fai clic su CREA, segui i passaggi facoltativi per concedere l'accesso al progetto e agli utenti e fai clic su FINE.
La scelta del ruolo per l'account di servizio non ha alcun effetto sulle chiamate che è possibile effettuare all'API Content, in quanto l'accesso ai metodi dell'API è determinato invece dal ruolo associato all'ID account di servizio in Merchant Center. Se hai dubbi su cosa scegliere, seleziona Progetto > Visualizzatore.
- Verrà visualizzata la pagina Account di servizio, in cui potrai accedere al nuovo account di servizio.
- Per ottenere una chiave privata JSON, fai clic sull'account di servizio, quindi sulla scheda CHIAVI. Fai clic su AGGIUNGI CHIAVE > Crea nuova chiave, quindi seleziona JSON come tipo di chiave. Fai clic su CREA per scaricare la chiave privata sul computer.
- Aggiungi il nuovo account di servizio come utente al tuo account Merchant Center. Se sei uno sviluppatore di terze parti, dovrai chiedere al cliente di eseguire questo passaggio al posto tuo.
- Accedi al tuo account
Merchant Center.
- Vai ad Accesso all'account nelle impostazioni del tuo account
Merchant Center.
- Fai clic su + Aggiungi utente e utilizza l'ID account di servizio come indirizzo email per il nuovo utente.
Se non hai preso nota dell'ID account di servizio in precedenza, vai alla pagina di amministrazione degli account di servizio e seleziona il progetto che hai creato.
- Specifica le preferenze per Accesso utente e Notifiche via email per l'account di servizio. Tieni presente che l'utilizzo del servizio
Accounts
richiede l'accesso Amministratore.
- Fai clic su Aggiungi utente per salvare le preferenze e tornare all'elenco
di utenti. L'ID account di servizio deve essere elencato con il ruolo
dell'utente scelto.
- Ripeti la procedura per tutti gli altri account di servizio da aggiungere.
- Ora puoi accedere al tuo account Merchant Center utilizzando l'account di servizio
tramite il flusso Credenziali predefinite dell'applicazione Google o tramite il flusso dell'account di servizio. Gli esempi dell'API Content for Shopping mostrano come utilizzare entrambi i flussi per le credenziali degli account di servizio in ogni linguaggio di programmazione supportato.
Consulta gli esempi di codice per provare il nuovo account di servizio e scoprire quali modifiche dovrai apportare per utilizzare gli account di servizio nel tuo codice.
Domande frequenti
- Posso accedere all'interfaccia utente di Merchant Center con il mio account di servizio?
- No, gli account di servizio non sono normali Account Google e non possono accedere all'interfaccia utente di Merchant Center.
- Con quale frequenza devo aggiornare i token di accesso all'account di servizio?
- I token di accesso scadono un'ora dopo essere stati emessi dal server di autorizzazione OAuth 2.0 di Google. Quando un token di accesso scade, l'applicazione deve utilizzare la libreria client per recuperare un altro token di accesso.
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-08-29 UTC.
[null,null,["Ultimo aggiornamento 2025-08-29 UTC."],[[["\u003cp\u003eService accounts enable applications to programmatically access Google APIs, including the Content API for Shopping, using OAuth 2.0 without human intervention.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize service accounts, you need to generate service account credentials, add the service account as a user in your Merchant Center account, and then access your Merchant Center account using either the Google Application Default Credentials flow or the service account flow.\u003c/p\u003e\n"],["\u003cp\u003eApplications authenticated with service accounts can only access your own Merchant Center account; for third-party applications needing access to client accounts, refer to the Authorizing Requests guide.\u003c/p\u003e\n"],["\u003cp\u003eService accounts cannot be used to sign in to the Merchant Center UI and access tokens expire after one hour, requiring the application to fetch a new one using the client library.\u003c/p\u003e\n"]]],["Service accounts allow applications to access the Content API for Shopping programmatically. Key actions include: generating service account credentials by creating an OAuth 2.0 Client ID and a JSON private key file via the Google API Console, and adding the service account as a user within the Merchant Center account, specifying access and notification preferences. To access the Merchant center, you can use Google Application Default Credentials or a service account flow, with example code available. Access tokens expire hourly, requiring renewal.\n"],null,["# Service accounts are special Google accounts that can be used by\napplications to access Google APIs programmatically via OAuth 2.0. A service\naccount uses an OAuth 2.0 flow that does not require human authorization.\nInstead, it uses a key file that only your application can access. This guide\ndiscusses how to access the Content API for Shopping with service accounts.\n\n**Note:** Applications using service accounts\nfor authentication can only access your own Merchant Center account. If you are\nwriting a third-party application that needs access to your clients' Merchant\nCenter accounts, please see the [Authorizing Requests](/shopping-content/guides/how-tos/authorizing)\nguide instead.\n\nPrerequisites\n-------------\n\n- A [Merchant Center](//merchants.google.com/) account.\n\nSteps to using a service account to access the Content API for Shopping\n-----------------------------------------------------------------------\n\n1. Generate service account credentials or access the public credentials you've already generated. You will need to create an OAuth 2.0 Client ID and obtain a \\*.json private key file:\n 1. Go to the [Google API Console](https://console.cloud.google.com/apis/library).\n 2. Select a project in the drop-down menu at the top of the page. If you do not have one yet, create one by clicking **NEW PROJECT**.\n 3. If you have not already enabled the Content API for Shopping for this project, then search for it in the list of Google APIs and enable it.\n 4. In the sidebar on the left, select **Credentials**. You may need to click the left-pointing arrow at the top left to see this.\n 5. To set up a service account, select **CREATE CREDENTIALS** , and then **Service account** . \n 6. Name the new service account. This also serves as the default username for the service account ID. Record the service account ID, including the part after the '@' character, for later use. Click **CREATE** , then go through the optional steps of granting access to project and users, and click **DONE** .\n\n The choice of role for the service account will not\n have any effect on what calls can be made to the Content API, as access to\n Content API methods is determined instead by the role associated with the\n service account ID in Merchant Center. If you are unsure what to pick, just\n pick **Project \\\u003e Viewer**.\n 7. You will be directed to the Service Accounts page where your new service account can be accessed.\n 8. To obtain a JSON private key, click on the service account, then the **KEYS** tab. Click **ADD KEY \\\u003e Create new key** and then select JSON as the key type. Click **CREATE** to download the private key to your computer.\n2. Add the new service account as a user to your Merchant Center account. If you are a third-party developer, you will need to have your client do this step for you.\n 1. Go to your [Merchant\n Center account](//merchants.google.com/).\n 2. Go to **Account Access** in the settings of your Merchant Center account.\n 3. Click **+ Add user** and use the service account ID as the email address for the new user.\n\n If you did not take note of the\n service account ID earlier, go to the [Service\n Accounts](//console.developers.google.com/iam-admin/serviceaccounts/) administration page and select the project you created.\n 4. Specify the **User access** and **Email notifications** preferences for the service account. Note that the use of the `Accounts` service requires **Admin** access.\n 5. Click **Add user** to save preferences and be returned to the list of users. The service account ID should be listed with the chosen user role.\n 6. Repeat the process for all other service accounts you want to add.\n3. Now you can access your Merchant Center account using the service account either by using the [Google Application\n Default Credentials](/identity/protocols/application-default-credentials) flow or by using the [service account flow](/identity/protocols/OAuth2ServiceAccount) directly. The Content API for Shopping [Samples](/shopping-content/guides/libraries) show how to use both flows for service account credentials in each supported programming language. Please check out the code samples to try out your new service account and to learn what changes you will need to use service accounts in your own code.\n\nFrequently asked questions\n--------------------------\n\nCan I sign in to the Merchant Center UI with my service account?\n: No, service accounts are not regular Google accounts and cannot access the\n Merchant Center UI.\n\nHow often do I need to refresh service account access tokens?\n: Access tokens expire one hour after they are issued by the Google OAuth 2.0\n Authorization Server. When an access token expires, the application should use\n the client library to fetch another access token."]]