Pengumuman: Semua project nonkomersial yang terdaftar untuk menggunakan Earth Engine sebelum
15 April 2025 harus
memverifikasi kelayakan nonkomersial untuk mempertahankan akses Earth Engine.
ee.data.authenticateViaOauth
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Mengonfigurasi autentikasi sisi klien panggilan EE API melalui Library Klien Google API untuk JavaScript. Pustaka akan dimuat secara otomatis jika belum dimuat di halaman. Pengguna akan diminta untuk memberikan akses ke data EE mereka kepada aplikasi yang diidentifikasi oleh clientId jika mereka belum melakukannya sebelumnya.
Metode autentikasi ini atau metode autentikasi lainnya harus dipanggil sebelum ee.initialize().
Perhatikan bahwa jika pengguna belum pernah memberikan akses ke aplikasi yang diidentifikasi oleh ID klien, secara default, hal ini akan mencoba memunculkan jendela dialog yang meminta pengguna untuk memberikan izin yang diperlukan. Namun, pop-up ini dapat diblokir oleh browser. Untuk menghindarinya, tentukan callback opt_onImmediateFailed, dan di dalamnya, render tombol login dalam halaman, lalu panggil ee.data.authenticateViaPopup() dari pengendali peristiwa klik tombol ini. Hal ini menghentikan browser memblokir pop-up, karena sekarang merupakan hasil langsung dari tindakan pengguna.
Token autentikasi akan diperbarui secara otomatis jika memungkinkan. Anda dapat mengasumsikan dengan aman bahwa semua panggilan asinkron akan dikirim dengan kredensial yang sesuai. Namun, untuk panggilan sinkron, Anda harus memeriksa token autentikasi dengan ee.data.getAuthToken() dan memanggil ee.data.refreshAuthToken() secara manual jika tidak ada. Operasi penggantian token bersifat asinkron dan tidak dapat dilakukan di balik layar sesuai permintaan sebelum panggilan sinkron.
Penggunaan | Hasil |
---|
ee.data.authenticateViaOauth(clientId, success, error, extraScopes, onImmediateFailed, suppressDefaultScopes) | |
Argumen | Jenis | Detail |
---|
clientId | String | Client ID OAuth aplikasi, atau null untuk menonaktifkan panggilan yang diautentikasi. Hal ini dapat diperoleh melalui Konsol Developer Google. Project harus memiliki asal JavaScript yang sesuai dengan domain tempat skrip berjalan. |
success | Fungsi | Fungsi yang akan dipanggil jika autentikasi berhasil. |
error | Fungsi, opsional | Fungsi yang akan dipanggil jika autentikasi gagal, meneruskan pesan error. Jika autentikasi dalam mode langsung
(di balik layar) gagal dan opt_onImmediateFailed ditentukan, fungsi tersebut akan dipanggil, bukan opt_error. |
extraScopes | List<String>, opsional | Cakupan OAuth tambahan yang akan diminta. |
onImmediateFailed | Fungsi, opsional | Fungsi yang akan dipanggil jika autentikasi otomatis di balik layar gagal. Default ke ee.data.authenticateViaPopup(), yang terikat ke callback yang diteruskan. |
suppressDefaultScopes | Boolean, opsional | Jika benar, hanya cakupan yang ditentukan dalam opt_extraScopes yang diminta; cakupan default tidak diminta kecuali jika ditentukan secara eksplisit dalam opt_extraScopes. |
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-25 UTC.
[null,null,["Terakhir diperbarui pada 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. |"]]