ee.data.authenticateViaOauth
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Konfiguriert die clientseitige Authentifizierung von EE API-Aufrufen über die Google APIs-Clientbibliothek für JavaScript. Die Bibliothek wird automatisch geladen, wenn sie noch nicht auf der Seite geladen ist. Der Nutzer wird aufgefordert, der durch „clientId“ identifizierten Anwendung Zugriff auf seine EE-Daten zu gewähren, sofern er dies noch nicht getan hat.
Diese oder eine andere Authentifizierungsmethode sollte vor ee.initialize() aufgerufen werden.
Wenn der Nutzer der durch die Client-ID identifizierten Anwendung noch keinen Zugriff gewährt hat, wird standardmäßig ein Dialogfeld eingeblendet, in dem der Nutzer aufgefordert wird, die erforderliche Berechtigung zu erteilen. Dieses Pop-up kann jedoch vom Browser blockiert werden. Um dies zu vermeiden, geben Sie den Callback „opt_onImmediateFailed“ an und rendern Sie darin eine Anmeldeschaltfläche auf der Seite. Rufen Sie dann „ee.data.authenticateViaPopup()“ über den Click-Ereignishandler dieser Schaltfläche auf. Dadurch wird verhindert, dass der Browser das Pop-up blockiert, da es nun die direkte Folge einer Nutzeraktion ist.
Das Autorisierungstoken wird nach Möglichkeit automatisch aktualisiert. Sie können davon ausgehen, dass alle asynchronen Aufrufe mit den entsprechenden Anmeldedaten gesendet werden. Bei synchronen Aufrufen sollten Sie jedoch mit ee.data.getAuthToken() nach einem Authentifizierungstoken suchen und ee.data.refreshAuthToken() manuell aufrufen, wenn keines vorhanden ist. Die Tokenaktualisierung erfolgt asynchron und kann nicht bei Bedarf im Hintergrund vor synchronen Aufrufen durchgeführt werden.
Nutzung | Ausgabe |
---|
ee.data.authenticateViaOauth(clientId, success, error, extraScopes, onImmediateFailed, suppressDefaultScopes) | |
Argument | Typ | Details |
---|
clientId | String | Die OAuth-Client-ID der Anwendung oder „null“, um authentifizierte Aufrufe zu deaktivieren. Sie können sie über die Google Developers Console abrufen. Das Projekt muss einen JavaScript-Ursprung haben, der der Domain entspricht, in der das Script ausgeführt wird. |
success | Funktion | Die Funktion, die aufgerufen werden soll, wenn die Authentifizierung erfolgreich war. |
error | Funktion (optional) | Die Funktion, die aufgerufen werden soll, wenn die Authentifizierung fehlgeschlagen ist, und die Fehlermeldung. Wenn die Authentifizierung im sofortigen (im Hintergrund) Modus fehlschlägt und opt_onImmediateFailed angegeben ist, wird diese Funktion anstelle von opt_error aufgerufen. |
extraScopes | List<String>, optional | Zusätzliche OAuth-Bereiche, die angefordert werden sollen. |
onImmediateFailed | Funktion (optional) | Die Funktion, die aufgerufen werden soll, wenn die automatische Authentifizierung im Hintergrund fehlschlägt. Standardmäßig wird ee.data.authenticateViaPopup() verwendet, das an die übergebenen Callbacks gebunden ist. |
suppressDefaultScopes | Boolesch, optional | Wenn „true“, werden nur die in „opt_extraScopes“ angegebenen Bereiche angefordert. Die Standardbereiche werden nur angefordert, wenn sie explizit in „opt_extraScopes“ angegeben sind. |
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2025-07-25 (UTC).
[null,null,["Zuletzt aktualisiert: 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. |"]]