Annuncio: tutti i progetti non commerciali registrati per l'utilizzo di Earth Engine prima del
15 aprile 2025 devono
verificare l'idoneità non commerciale per mantenere l'accesso a Earth Engine.
ee.data.authenticateViaOauth
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Configura l'autenticazione lato client delle chiamate API EE tramite la libreria client delle API di Google per JavaScript. La libreria verrà caricata automaticamente se non è già caricata nella pagina. All'utente verrà chiesto di concedere all'applicazione identificata da clientId l'accesso ai propri dati EE, se non l'ha già fatto.
Questo o un altro metodo di autenticazione deve essere chiamato prima di ee.initialize().
Tieni presente che, se l'utente non ha precedentemente concesso l'accesso all'applicazione identificata dall'ID client, per impostazione predefinita verrà visualizzata una finestra di dialogo che chiede all'utente di concedere l'autorizzazione richiesta. Tuttavia, questo popup può essere bloccato dal browser. Per evitare questo problema, specifica il callback opt_onImmediateFailed e al suo interno esegui il rendering di un pulsante di accesso nella pagina, quindi chiama ee.data.authenticateViaPopup() dal gestore eventi di clic di questo pulsante. In questo modo, il browser non blocca il popup, in quanto è il risultato diretto di un'azione utente.
Il token di autenticazione verrà aggiornato automaticamente quando possibile. Puoi dare per scontato che tutte le chiamate asincrone verranno inviate con le credenziali appropriate. Per le chiamate sincrone, tuttavia, devi verificare la presenza di un token di autenticazione con ee.data.getAuthToken() e chiamare ee.data.refreshAuthToken() manualmente se non è presente. L'operazione di aggiornamento del token è asincrona e non può essere eseguita in background su richiesta prima delle chiamate sincrone.
Utilizzo | Resi |
---|
ee.data.authenticateViaOauth(clientId, success, error, extraScopes, onImmediateFailed, suppressDefaultScopes) | |
Argomento | Tipo | Dettagli |
---|
clientId | Stringa | L'ID client OAuth dell'applicazione o null per disattivare le chiamate autenticate. Puoi ottenerlo tramite Google Developers Console. Il progetto deve avere un'origine JavaScript che corrisponda al dominio in cui viene eseguito lo script. |
success | Funzione | La funzione da chiamare se l'autenticazione è riuscita. |
error | Funzione, facoltativa | La funzione da chiamare se l'autenticazione non è riuscita, ha superato il messaggio di errore. Se l'autenticazione in modalità immediata
(in background) non va a buon fine e viene specificata opt_onImmediateFailed, viene chiamata questa funzione anziché opt_error. |
extraScopes | List<String>, facoltativo | Ambiti OAuth aggiuntivi da richiedere. |
onImmediateFailed | Funzione, facoltativa | La funzione da chiamare se l'autenticazione automatica in background non va a buon fine. Il valore predefinito è ee.data.authenticateViaPopup(), associato ai callback passati. |
suppressDefaultScopes | Booleano, facoltativo | Se il valore è true, vengono richiesti solo gli ambiti specificati in opt_extraScopes; gli ambiti predefiniti non vengono richiesti, a meno che non siano specificati esplicitamente in opt_extraScopes. |
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-07-25 UTC.
[null,null,["Ultimo aggiornamento 2025-07-25 UTC."],[[["\u003cp\u003eEnables authenticated access to Earth Engine data using your Google account via the Google APIs Client Library for JavaScript.\u003c/p\u003e\n"],["\u003cp\u003eRequires initialization before using Earth Engine functionalities and might prompt users for permission to access their Earth Engine data.\u003c/p\u003e\n"],["\u003cp\u003eAutomatically refreshes authentication tokens for asynchronous calls, but synchronous calls may require manual token refresh using \u003ccode\u003eee.data.getAuthToken()\u003c/code\u003e and \u003ccode\u003eee.data.refreshAuthToken()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eProvides options for handling authentication failures, including specifying custom error callbacks and displaying an in-page login button to avoid browser popup blockers.\u003c/p\u003e\n"],["\u003cp\u003eAllows customization of OAuth scopes and client ID for specific application requirements.\u003c/p\u003e\n"]]],[],null,["# ee.data.authenticateViaOauth\n\n\u003cbr /\u003e\n\nConfigures client-side authentication of EE API calls through the Google APIs Client Library for JavaScript. The library will be loaded automatically if it is not already loaded on the page. The user will be asked to grant the application identified by clientId access to their EE data if they have not done so previously.\n\n\u003cbr /\u003e\n\nThis or another authentication method should be called before ee.initialize().\n\nNote that if the user has not previously granted access to the application identified by the client ID, by default this will try to pop up a dialog window prompting the user to grant the required permission. However, this popup can be blocked by the browser. To avoid this, specify the opt_onImmediateFailed callback, and in it render an in-page login button, then call ee.data.authenticateViaPopup() from the click event handler of this button. This stops the browser from blocking the popup, as it is now the direct result of a user action.\n\nThe auth token will be refreshed automatically when possible. You can safely assume that all async calls will be sent with the appropriate credentials. For synchronous calls, however, you should check for an auth token with ee.data.getAuthToken() and call ee.data.refreshAuthToken() manually if there is none. The token refresh operation is asynchronous and cannot be performed behind-the-scenes on-demand prior to synchronous calls.\n\n| Usage | Returns |\n|------------------------------------------------------------------------------------------------------------------------------------|---------|\n| `ee.data.authenticateViaOauth(clientId, success, `*error* `, `*extraScopes* `, `*onImmediateFailed* `, `*suppressDefaultScopes*`)` | |\n\n| Argument | Type | Details |\n|-------------------------|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `clientId` | String | The application's OAuth client ID, or null to disable authenticated calls. This can be obtained through the Google Developers Console. The project must have a JavaScript origin that corresponds to the domain where the script is running. |\n| `success` | Function | The function to call if authentication succeeded. |\n| `error` | Function, optional | The function to call if authentication failed, passed the error message. If authentication in immediate (behind-the-scenes) mode fails and opt_onImmediateFailed is specified, that function is called instead of opt_error. |\n| `extraScopes` | List\\\u003cString\\\u003e, optional | Extra OAuth scopes to request. |\n| `onImmediateFailed` | Function, optional | The function to call if automatic behind-the-scenes authentication fails. Defaults to ee.data.authenticateViaPopup(), bound to the passed callbacks. |\n| `suppressDefaultScopes` | Boolean, optional | When true, only scopes specified in opt_extraScopes are requested; the default scopes are not requested unless explicitly specified in opt_extraScopes. |"]]