Stai visualizzando la documentazione precedente relativa all'API della libreria di Google Foto.
Inizia a utilizzare REST
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Per iniziare a utilizzare l'API della libreria di Google Foto, configura il tuo progetto abilitando l'API tramite
la console API di Google e configurare un ID client OAuth 2.0.
La tua applicazione interagisce con Google Foto per conto di un
Utente di Google Foto. Ad esempio, quando crei album nella cartella
raccolta di Google Foto o caricare elementi multimediali nella cartella
Google Foto, l'utente autorizza queste richieste API tramite
OAuth 2.0.
L'ID client OAuth 2.0 consente agli utenti dell'applicazione di accedere, autenticarsi
e quindi utilizzare l'API Library. L'API Library non supporta
account di servizio; per utilizzare questa API, gli utenti devono aver effettuato l'accesso a un
Account.
Abilita l'API
Prima di poter utilizzare l'API Library, devi abilitarla per il tuo progetto.
- Vai alla console dell'API di Google.
- Dalla barra dei menu, seleziona un progetto o creane uno nuovo.
- Per aprire la libreria API di Google, dal menu di navigazione seleziona
API e Servizi > Raccolta.
- Cerca "API Google Foto Library". Seleziona il risultato corretto e fai clic
Attiva.
Richiedere un ID client OAuth 2.0
Segui questi passaggi per richiedere un ID client OAuth e configurarlo per il tuo
un'applicazione. Questo esempio utilizza un'applicazione in cui l'intero flusso OAuth
gestito lato server, come quello nei nostri campioni. La procedura di configurazione può variare
per altri scenari di implementazione.
- Vai alla console API di Google.
e seleziona il tuo progetto.
- Dal menu, seleziona API e Servizi > Credenziali.
- Nella pagina Credenziali, fai clic su Crea credenziali > ID client OAuth.
- Seleziona il Tipo di applicazione. In questo esempio, il tipo di applicazione è
Applicazione web.
Registra le origini da cui la tua app è autorizzata ad accedere alle API di Google
come segue:
- Per identificare l'ID client, inserisci un nome.
Nel campo Origini JavaScript autorizzate, inserisci l'origine del tuo
dell'app. In questo campo non sono consentiti caratteri jolly.
Puoi inserire più origini per consentire l'esecuzione dell'app su diverse
protocolli, domini o sottodomini. Gli URL inseriti possono essere
avviare una richiesta OAuth.
L'esempio seguente mostra un URL di sviluppo locale (i nostri esempi utilizzano
localhost:8080
) e un URL di produzione.
http://localhost:8080
https://myproductionurl.example.com
Il campo URI di reindirizzamento autorizzato è l'endpoint che riceve
dal server OAuth 2.0. In genere, sono inclusi
dell'ambiente di sviluppo e rimanda a un percorso nell'applicazione.
http://localhost:8080/auth/google/callback
https://myproductionurl.example.com/auth/google/callback
Fai clic su Crea.
-
Dalla finestra di dialogo del client OAuth risultante, copia quanto segue:
La tua app può accedere alle API di Google abilitate utilizzando questi valori.
Prima di poter avviare un'applicazione pubblica che accede all'API Library,
la tua app deve essere esaminata da Google. Un'"App non verificata" viene visualizzato
schermata quando si testa l'applicazione, finché non viene
verificati.
Prova l'anteprima
Ora che hai configurato il progetto per l'utilizzo con l'API Library,
Dai un'occhiata all'app di esempio su GitHub. App di esempio
dimostra come creare una cornice digitale intelligente utilizzando l'API Library.
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\u003eTo use the Google Photos Library API, you must enable the API and set up an OAuth 2.0 client ID through the Google API Console.\u003c/p\u003e\n"],["\u003cp\u003eUsers must be signed in to a valid Google Account to use the Library API as it requires user authorization via OAuth 2.0 for actions like creating albums or uploading media.\u003c/p\u003e\n"],["\u003cp\u003eBefore launching publicly, your application needs to be reviewed and verified by Google to remove the "Unverified app" message during testing.\u003c/p\u003e\n"]]],["To utilize the Google Photos Library API, first enable it for your project in the Google API Console. Then, create an OAuth 2.0 client ID, specifying the application type, authorized JavaScript origins, and redirect URIs. Obtain the client ID and secret from the resulting dialog. Ensure your application is reviewed by Google before public launch. Note, only valid Google Account users can use this API as service accounts aren't supported.\n"],null,["# Get started with REST\n\nTo start using the Google Photos Library API, configure your project by enabling the API via\nthe Google API Console and setting up an OAuth 2.0 client ID.\n\nYour application interacts with Google Photos on behalf of a\nGoogle Photos user. For instance, when you create albums in a user's\nGoogle Photos library or upload media items to a user's\nGoogle Photos account, the user authorizes these API requests via the\n[OAuth 2.0](/identity/protocols/OAuth2) protocol.\n\nThe OAuth 2.0 client ID allows your application users to sign in, authenticate,\nand thereby use the Library API. The Library API does not support\nservice accounts; to use this API, users must be signed in to a valid Google\nAccount.\n\nConfigure your app\n------------------\n\n### Enable the API\n\nBefore you can use the Library API, you must enable it for your project.\n\n1. Go to the [Google API Console](https://console.developers.google.com/apis/library).\n2. From the menu bar, select a project or create a new project.\n3. To open the Google API Library, from the Navigation menu, select **APIs \\& Services \\\u003e Library**.\n4. Search for \"Google Photos Library API\". Select the correct result and click **Enable**.\n\n### Request an OAuth 2.0 client ID\n\nFollow the steps below to request an OAuth client ID and configure it for your\napplication. This example uses an application where the entire OAuth flow is\nhandled server-side, such as the one in our samples. The setup process may vary\nfor other [implementation scenarios](/identity/protocols/OAuth2).\n\n1. Go to the [Google API Console](https://console.developers.google.com/apis/library) and select your project.\n2. From the menu, select **APIs \\& Services \\\u003e Credentials**.\n3. On the **Credentials** page, click **Create Credentials \\\u003e OAuth client ID**.\n4. Select your **Application type** . In this example, the application type is **Web application**.\n5. Register the origins from which your app is allowed to access the Google APIs\n as follows:\n\n 1. To identify the client ID, enter a name.\n 2. In the **Authorized JavaScript origins** field, enter the origin for your\n app. This field doesn't allow wildcards.\n\n You can enter multiple origins to allow your app to run on different\n protocols, domains, or subdomains. The URLs you enter are allowed to\n start an OAuth request.\n\n The following example shows a local development URL (our samples use\n `localhost:8080`) and a production URL. \n\n http://localhost:8080\n https://myproductionurl.example.com\n\n 3. The **Authorized redirect URI** field is the endpoint that receives\n responses from the OAuth 2.0 server. Typically, this includes your\n development environment and points to a path in your application.\n\n http://localhost:8080/auth/google/callback\n https://myproductionurl.example.com/auth/google/callback\n\n 4. Click **Create**.\n\n\u003c!-- --\u003e\n\n6. From the resulting OAuth client dialog, copy the following:\n\n - Client ID\n - Client secret\n\n Your app can access the enabled Google APIs using these values.\n\nBefore you can launch a public application that accesses the Library API,\nyour app must be reviewed by Google. An \"Unverified app\" message appears on the\nscreen when you test your application, until it is\n[verified](https://support.google.com/cloud/answer/7454865).\n\nTry out the sample\n------------------\n\nNow that you've configured your project for use with the Library API,\ncheck out the [sample app](/photos/library/samples) on GitHub. The sample app\ndemonstrates how you can build a smart photo frame using the Library API."]]