gpt4 book ai didi

node.js - js应用程序API错误: Forbidden accessing App Engine datastore from local Node.

转载 作者:太空宇宙 更新时间:2023-11-03 21:58:07 28 4
gpt4 key购买 nike

我有一个应用程序部署到 App Engine,并且希望从我本地运行的 Node.js 应用程序访问该应用程序的数据存储区。我从 Hello World app for Node 开始并尝试从我部署的应用程序的数据存储中检索实体并将其记录到控制台 this documentation 。我的 Node 应用程序代码如下。

var express = require('express');
var gcloud = require('gcloud')({
projectId: 'myProjectId',
keyFilename: __dirname + 'myKeyfile.json'
});
var datastore = gcloud.datastore;
var dataset = datastore.dataset();

var app = express();

app.get('/', function(req, res) {
dataset.get(dataset.key(['Practice', 4392384]), function(err, entity) {
if (err) {
console.log("ERROR: " + err);
} else {
console.log("Practice entity: " + entity);
}
});
res.status(200).send('Hello, world!');
});

var server = app.listen(process.env.PORT || 8081, function () {
var host = server.address().address;
var port = server.address().port;

console.log('App listening at http://%s:%s', host, port);
});

我已在我的 App Engine 应用程序中按照 these directions 设置了一个服务帐户(在“从另一个平台访问现有的 App Engine 数据存储区”标题下)并生成了一个 JSON key 文件,该文件位于 Node 项目的根目录(与 app.js 相同的目录)中。当尝试从数据存储区获取有效实体时,我记录错误“ApiError:Forbidden”。我只能推测 App Engine 项目未正确配置服务帐户或未正确启用 Cloud Datastore API,那么我是否明显做错了什么,或者有什么方法可以获取有关返回的错误的更多详细信息?

最佳答案

我在几个小时内(2016 年 1 月 15 日期间)遇到了同样的问题。然后 Node.js 代码再次开始工作,无需进行任何更改,我现在可以访问数据存储区 API。显然这是 Google 云服务中的一个临时问题。

关于node.js - js应用程序API错误: Forbidden accessing App Engine datastore from local Node.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34794975/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com