お知らせ:
2025 年 4 月 15 日より前に Earth Engine の使用を登録したすべての非商用プロジェクトは、Earth Engine へのアクセスを維持するために
非商用目的での利用資格を確認する必要があります。
ee.data.authenticateViaOauth
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
JavaScript 用 Google API クライアント ライブラリを使用して、EE API 呼び出しのクライアントサイド認証を構成します。ライブラリがページにまだ読み込まれていない場合は、自動的に読み込まれます。ユーザーが以前に clientId で識別されるアプリに EE データへのアクセス権を付与していない場合は、アクセス権を付与するよう求められます。
このメソッドまたは別の認証メソッドは、ee.initialize() の前に呼び出す必要があります。
ユーザーがクライアント ID で識別されるアプリへのアクセスを以前に許可していない場合、デフォルトでは、必要な権限を付与するようユーザーに求めるダイアログ ウィンドウが表示されます。ただし、このポップアップはブラウザによってブロックされる可能性があります。これを回避するには、opt_onImmediateFailed コールバックを指定し、その中でページ内ログイン ボタンをレンダリングしてから、このボタンのクリック イベント ハンドラから ee.data.authenticateViaPopup() を呼び出します。これにより、ポップアップがユーザー アクションの直接的な結果となるため、ブラウザによるポップアップのブロックが停止します。
認証トークンは、可能な場合は自動的に更新されます。すべての非同期呼び出しは適切な認証情報とともに送信されると想定して問題ありません。ただし、同期呼び出しの場合は、ee.data.getAuthToken() で認証トークンを確認し、認証トークンがない場合は ee.data.refreshAuthToken() を手動で呼び出す必要があります。トークン更新オペレーションは非同期であり、同期呼び出しの前にオンデマンドでバックグラウンドで実行することはできません。
用途 | 戻り値 |
---|
ee.data.authenticateViaOauth(clientId, success, error, extraScopes, onImmediateFailed, suppressDefaultScopes) | |
引数 | タイプ | 詳細 |
---|
clientId | 文字列 | アプリケーションの OAuth クライアント ID。認証された呼び出しを無効にする場合は 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 で明示的に指定されていない限り、デフォルトのスコープはリクエストされません。 |
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 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. |"]]