公告:所有在
2025 年 4 月 15 日之前注册使用 Earth Engine 的非商业项目都必须
验证是否符合非商业性质的资格条件,才能继续使用 Earth Engine。
ee.data.authenticateViaPrivateKey
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
通过 Google API Node.js 客户端配置 EE API 调用的服务器端身份验证。私钥身份验证仅适用于服务器端 API 调用:对于基于浏览器的应用,请使用 ee.data.authenticateViaOauth()。使用服务器端身份验证时,无需进行用户互动(例如身份验证弹出式窗口)。
应在 ee.initialize() 之前调用此方法或其他身份验证方法。
系统会在可能的情况下自动刷新身份验证令牌。您可以放心地假设所有异步调用都将使用适当的凭据发送。不过,对于同步调用,您应使用 ee.data.getAuthToken() 检查是否存在身份验证令牌,如果没有,则手动调用 ee.data.refreshAuthToken()。令牌刷新操作是异步的,无法在同步调用之前按需在后台执行。
用法 | 返回 |
---|
ee.data.authenticateViaPrivateKey(privateKey, success, error, extraScopes, suppressDefaultScopes) | |
参数 | 类型 | 详细信息 |
---|
privateKey | AuthPrivateKey | 私钥的 JSON 内容。 |
success | 函数(可选) | 如果身份验证成功,要调用的函数。 |
error | 函数(可选) | 如果身份验证失败,则要调用的函数,并传递错误消息。 |
extraScopes | List<String>,可选 | 要请求的额外 OAuth 范围。 |
suppressDefaultScopes | 布尔值,可选 | 如果为 true,则仅请求 opt_extraScopes 中指定的作用域;除非在 opt_extraScopes 中明确指定,否则不会请求默认作用域。 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eEnables server-side authentication for Earth Engine API calls using a private key, suitable for non-browser environments.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication happens automatically for asynchronous calls, but synchronous calls require manual token checks and refresh using \u003ccode\u003eee.data.getAuthToken()\u003c/code\u003e and \u003ccode\u003eee.data.refreshAuthToken()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eee.data.authenticateViaPrivateKey()\u003c/code\u003e function facilitates this authentication process, accepting the private key and optional success/error callbacks, extra scopes, and a flag to suppress default scopes.\u003c/p\u003e\n"]]],[],null,["# ee.data.authenticateViaPrivateKey\n\n\u003cbr /\u003e\n\nConfigures server-side authentication of EE API calls through the Google APIs Node.js Client. Private key authentication is strictly for server-side API calls: for browser-based applications, use ee.data.authenticateViaOauth(). No user interaction (e.g. authentication popup) is necessary when using server-side authentication.\n\n\u003cbr /\u003e\n\nThis or another authentication method should be called before ee.initialize().\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.authenticateViaPrivateKey(privateKey, `*success* `, `*error* `, `*extraScopes* `, `*suppressDefaultScopes*`)` | |\n\n| Argument | Type | Details |\n|-------------------------|--------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `privateKey` | AuthPrivateKey | JSON content of private key. |\n| `success` | Function, optional | The function to call if authentication succeeded. |\n| `error` | Function, optional | The function to call if authentication failed, passed the error message. |\n| `extraScopes` | List\\\u003cString\\\u003e, optional | Extra OAuth scopes to request. |\n| `suppressDefaultScopes` | Boolean, optional | When true, only scopes specified in opt_extraScopes are requested; the default scopes are not not requested unless explicitly specified in opt_extraScopes. |"]]