ee.data.authenticateViaOauth
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
הגדרת אימות בצד הלקוח של קריאות ל-EE API דרך Google APIs Client Library for JavaScript. הספרייה תיטען באופן אוטומטי אם היא עדיין לא נטענה בדף. אם המשתמש לא העניק לאפליקציה שזוהתה על ידי clientId גישה לנתוני ה-EE שלו בעבר, הוא יתבקש לעשות זאת.
צריך להפעיל את שיטת האימות הזו או שיטת אימות אחרת לפני ee.initialize().
שימו לב: אם המשתמש לא העניק בעבר גישה לאפליקציה שמזוהה על ידי מזהה הלקוח, כברירת מחדל המערכת תנסה להציג חלון דו-שיח שבו המשתמש יתבקש להעניק את ההרשאה הנדרשת. עם זאת, הדפדפן יכול לחסום את החלון הקופץ הזה. כדי למנוע את הבעיה הזו, צריך לציין את הקריאה החוזרת opt_onImmediateFailed, ובמסגרתה להציג לחצן כניסה בדף, ואז לקרוא ל-ee.data.authenticateViaPopup() מתוך handler של אירוע הלחיצה של הלחצן הזה. כך הדפדפן לא יחסום את החלון הקופץ, כי הוא נובע ישירות מפעולה של המשתמש.
טוקן האימות יתעדכן אוטומטית כשזה אפשרי. אפשר להניח בבטחה שכל הקריאות האסינכרוניות יישלחו עם פרטי הכניסה המתאימים. עם זאת, עבור קריאות סינכרוניות, צריך לבדוק אם יש אסימון אימות באמצעות ee.data.getAuthToken() ולהפעיל את ee.data.refreshAuthToken() באופן ידני אם אין אסימון. פעולת רענון האסימון היא אסינכרונית, ואי אפשר לבצע אותה ברקע לפי דרישה לפני קריאות סינכרוניות.
שימוש | החזרות |
---|
ee.data.authenticateViaOauth(clientId, success, error, extraScopes, onImmediateFailed, suppressDefaultScopes) | |
ארגומנט | סוג | פרטים |
---|
clientId | מחרוזת | מזהה הלקוח של OAuth של האפליקציה, או null כדי להשבית שיחות מאומתות. אפשר לקבל את המזהה הזה דרך Google Developers Console. לפרויקט צריך להיות מקור JavaScript שמתאים לדומיין שבו הסקריפט פועל. |
success | פונקציה | הפונקציה שמופעלת אם האימות הצליח. |
error | פונקציה, אופציונלי | הפונקציה לקריאה אם האימות נכשל, והעברת הודעת השגיאה. אם האימות במצב מיידי (מאחורי הקלעים) נכשל והפונקציה opt_onImmediateFailed צוינה, הפונקציה הזו נקראת במקום opt_error. |
extraScopes | List<String>, אופציונלי | היקפי הרשאות נוספים של OAuth לבקשה. |
onImmediateFailed | פונקציה, אופציונלי | הפונקציה שמופעלת אם האימות האוטומטי ברקע נכשל. ברירת המחדל היא ee.data.authenticateViaPopup(), שמוגדרת לשיחות החוזרות שהועברו. |
suppressDefaultScopes | בוליאני, אופציונלי | אם הערך הוא true, נשלחת בקשה רק להיקפים שצוינו ב-opt_extraScopes. ההיקפים שמוגדרים כברירת מחדל לא נכללים בבקשה, אלא אם הם צוינו במפורש ב-opt_extraScopes. |
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-25 (שעון UTC).
[null,null,["עדכון אחרון: 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. |"]]