我正在尝试开发一个使用谷歌地球引擎进行一些地理空间数据分析的nodejs应用程序。我正在使用"@google/earthengine"; "^0.1.185",节点v16.4.2和npm v 7.18.1。我还使用gcloud创建了服务帐户,并按照步骤一步一步地安装Google Earth Engine npm。问题是,每次我调用一些地球引擎功能时,它只是给出错误:
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:blablablablanode_modules@googleearthenginebuildmain.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:blablablablanode_modules@googleearthenginebuildmain.js:15467:9)
at Object.ee.data.send_ (C:blablablablanode_modules@googleearthenginebuildmain.js:15390:18)
at Object.ee.data.getAlgorithms (C:blablablablanode_modules@googleearthenginebuildmain.js:14670:24)
at Function.ee.ApiFunction.initialize (C:blablablablanode_modules@googleearthenginebuildmain.js:15923:78)
at Object.ee.initialize (C:blablablablanode_modules@googleearthenginebuildmain.js:17722:26)
at blablablablaapp.js:36:10
at Object.ee.data.handleAuthResult_ (C:blablablablanode_modules@googleearthenginebuildmain.js:15497:16)
at blablablablanode_modules@googleearthenginebuildmain.js:14490:19
at blablablablanode_modules@googleearthenginebuildmain.js:14424:41
at blablablablanode_modulesgoogle-auth-librarylibauthjwtclient.js:119:5
我真的需要你的帮助。
似乎你的电脑甚至不能联系谷歌引擎服务服务器。也许你应该试着在另一台电脑上测试你的代码,这台电脑没有任何防火墙、代理或其他可能干扰你网络的东西。
另外,因为你在İstanbul, Istambul, Turquia
,偶尔会干扰谷歌的服务,确保谷歌地球引擎服务没有被封锁,当你测试。如果您确定是这种情况,那么您可能需要代理或vpn。或者如果你使用代理/vpn,确保代理/vpn允许谷歌引擎服务。