node.js - 尝试在 Node.js 服务器中连接 Google Earth Engine API 时出错

标签 node.js google-maps google-cloud-platform google-earth-engine

我正在尝试开发一个 nodejs 应用程序,该应用程序使用 Google 地球引擎进行一些地理空间数据分析。我正在使用 “@google/earthengine”:“^0.1.185”, Node v16.4.2 和 npm v 7.18.1。我还使用 gcloud 创建了服务帐户,并按照 Google Earth Engine npm installation 的逐步操作进行了操作。 .问题是,每次我调用一些地球引擎功能时,它只会给出错误:

throw ee.initializationFailure_(e), e;
          ^

Error: Failed to contact Earth Engine servers. Please check your connection, firewall, or browser extension settings
在我尝试连接到地球引擎时遇到 404 错误之前。我试图停用我的防火墙并更改我使用的互联网,但还是一样。
查看代码和错误:
const ee = require('@google/earthengine');
const path = require("path");
const express = require('express');
const app = express();
const privateKey = require('./privatekey.json');
const port = process.env.PORT || 4000;

app.set('views', __dirname + '/views');
//app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');

app.set("views", path.join(__dirname, "views"));
app.set("view engine", "html");


app.get('/', (_,res)=>{
  res.sendFile('index.html', {root : __dirname + '/views'});
});
// Define endpoint at /mapid.
app.get('/mapid', (_, response) => {
  // Instantiate an image with the Image constructor.
  var image = ee.Image('CGIAR/SRTM90_V4');

  // Zoom to a location.
  Map.setCenter(-112.8598, 36.2841, 9); // Center on the Grand Canyon.

  // Display the image on the map.
  Map.addLayer(image);
   
});

console.log('Authenticating Earth Engine API using private key...');

ee.data.authenticateViaPrivateKey(
    privateKey,
    () => {
      console.log('Authentication successful.');
      ee.initialize(() => {
        console.log('Earth Engine client library initialized.');
        app.listen(port);
        console.log(`Listening on port ${port}`);
      },
      (err) => {
       
        console.log(err);
       
      });
      
    },
    (err) => {
      
       console.log(err);
      
    });
 

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})
错误
C:\blablablabla\node_modules\@google\earthengine\build\main.js:17724
          throw ee.initializationFailure_(e), e;
          ^

Error: Failed to contact Earth Engine servers. Please check your connection, firewall, or browser extension settings.
    at Object.ee.data.handleResponse_ (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15467:9)
    at Object.ee.data.send_ (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15390:18)
    at Object.ee.data.getAlgorithms (C:\blablablabla\node_modules\@google\earthengine\build\main.js:14670:24)
    at Function.ee.ApiFunction.initialize (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15923:78)
    at Object.ee.initialize (C:\blablablabla\node_modules\@google\earthengine\build\main.js:17722:26)
    at blablablabla\app.js:36:10
    at Object.ee.data.handleAuthResult_ (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15497:16)
    at blablablabla\node_modules\@google\earthengine\build\main.js:14490:19
    at blablablabla\node_modules\@google\earthengine\build\main.js:14424:41
    at blablablabla\node_modules\google-auth-library\lib\auth\jwtclient.js:119:5
请我真的需要你的帮助。

最佳答案

看来你的电脑连谷歌引擎服务服务器都联系不上。也许您应该尝试在另一台没有任何防火墙、代理或其他任何可能干扰您的网络的计算机上测试您的代码。
另外,由于您在 İstanbul, Istambul, Turquia , 其中 interferes with Google services偶尔,请确保在测试时未阻止 google earth 引擎服务。如果您确定是这种情况,那么您可能需要代理或 VPN。或者,如果您使用代理/vpn,请确保代理/vpn 允许谷歌引擎服务。

关于node.js - 尝试在 Node.js 服务器中连接 Google Earth Engine API 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68929166/

相关文章:

node.js - 在进程退出之前运行异步函数

javascript - 如何将 JSON 数据插入父子表

node.js - 设备订阅 AWS IoT 上的主题

android - Google Maps Android API v2 抛出 GooglePlayServicesNotAvailableException,过期,SupportMapFragment.getMap() 返回 null

python - list_value 不能包含包含另一个 list_value 的 Value

Node.js 套接字同时发送和接收

javascript - 使用此谷歌地图 API 自动完成示例。修改这个函数可以得到经纬度吗?

android - 如何在谷歌地图 Android 上显示多个标记?

google-cloud-platform - Google Compute Engine - 为 root : mkdir/root/. ssh 更新 SSH key 时出错:只读文件系统

android - 无法创建 Android OAuth2 客户端 ID(重复指纹)