ee.data.authenticateViaOauth
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Konfiguruje uwierzytelnianie po stronie klienta wywołań interfejsu EE API za pomocą biblioteki klienta interfejsów API Google w JavaScripcie. Biblioteka zostanie wczytana automatycznie, jeśli nie jest jeszcze wczytana na stronie. Jeśli użytkownik nie udzielił wcześniej dostępu do danych EE aplikacji zidentyfikowanej przez clientId, pojawi się prośba o przyznanie takiego dostępu.
Tę lub inną metodę uwierzytelniania należy wywołać przed ee.initialize().
Pamiętaj, że jeśli użytkownik nie przyznał wcześniej dostępu aplikacji zidentyfikowanej przez identyfikator klienta, domyślnie pojawi się okno z prośbą o przyznanie wymaganych uprawnień. To wyskakujące okienko może jednak zostać zablokowane przez przeglądarkę. Aby tego uniknąć, określ wywołanie zwrotne opt_onImmediateFailed i wyrenderuj w nim przycisk logowania na stronie, a następnie wywołaj ee.data.authenticateViaPopup() z modułu obsługi zdarzeń kliknięcia tego przycisku. Dzięki temu przeglądarka nie zablokuje wyskakującego okienka, ponieważ będzie ono bezpośrednim wynikiem działania użytkownika.
Token uwierzytelniający będzie w miarę możliwości odświeżany automatycznie. Możesz bezpiecznie założyć, że wszystkie wywołania asynchroniczne będą wysyłane z odpowiednimi danymi logowania. W przypadku wywołań synchronicznych sprawdź jednak, czy jest dostępny token uwierzytelniania, używając funkcji ee.data.getAuthToken(), a jeśli go nie ma, wywołaj ręcznie funkcję ee.data.refreshAuthToken(). Operacja odświeżania tokena jest asynchroniczna i nie można jej wykonać w tle na żądanie przed wywołaniami synchronicznymi.
Wykorzystanie | Zwroty |
---|
ee.data.authenticateViaOauth(clientId, success, error, extraScopes, onImmediateFailed, suppressDefaultScopes) | |
Argument | Typ | Szczegóły |
---|
clientId | Ciąg znaków | Identyfikator klienta OAuth aplikacji lub wartość null, aby wyłączyć wywołania uwierzytelnione. Możesz go uzyskać w Google Developers Console. Projekt musi mieć źródło JavaScript, które odpowiada domenie, w której działa skrypt. |
success | Funkcja | Funkcja, która ma zostać wywołana, jeśli uwierzytelnianie się powiedzie. |
error | Funkcja (opcjonalnie) | Funkcja, którą należy wywołać w przypadku nieudanego uwierzytelniania, przekazała komunikat o błędzie. Jeśli uwierzytelnianie w trybie natychmiastowym (w tle) się nie powiedzie i określono opt_onImmediateFailed, zamiast opt_error wywoływana jest ta funkcja. |
extraScopes | List<String>, opcjonalnie | Dodatkowe zakresy protokołu OAuth, o które chcesz poprosić. |
onImmediateFailed | Funkcja (opcjonalnie) | Funkcja, która ma zostać wywołana, jeśli automatyczne uwierzytelnianie w tle się nie powiedzie. Domyślnie jest to funkcja ee.data.authenticateViaPopup() powiązana z przekazanymi funkcjami wywołania zwrotnego. |
suppressDefaultScopes | Wartość logiczna, opcjonalna | Jeśli ma wartość „true”, żądane są tylko zakresy określone w parametrze opt_extraScopes. Zakresy domyślne nie są żądane, chyba że zostały wyraźnie określone w parametrze opt_extraScopes. |
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-25 UTC.
[null,null,["Ostatnia aktualizacja: 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. |"]]