I'm building a webapp with google appengine, node.js and socket.io, and I'm currently trying to set up a google compute instance to use the google cloud datastore api following this tutorial. So far, I've completed steps 1 and 2, but when running the downloaded adams.js file locally, I get this:
我正在使用google appengine,node.js和socket.io构建一个webapp,我正在尝试设置一个google计算实例,以便在本教程之后使用google cloud datastore api。到目前为止,我已经完成了第1步和第2步,但是在本地运行下载的adams.js文件时,我得到了:
Error: No access or refresh token is set.
Stuff I've tried:
我试过的东西:
- gcloud auth login (this logs me in google, but doesn't set my token locally)
- changing the way I'm exporting my DATASTORE_SERVICE_ACCOUNT and DATASTORE_PRIVATE_KEY_FILE values, as strings, plain text, etc.
- logging my credentials on the line before the error (I'm definitely missing a token)
- creating a new service account and going through key creation steps again
- ran curl "https://metadata/computeMetadata/v1/instance/service-accounts/default/token" -D "Metadata-Flavor: Google" to get more info.
gcloud auth登录(这会将我登录到谷歌,但不会在本地设置我的令牌)
更改我导出DATASTORE_SERVICE_ACCOUNT和DATASTORE_PRIVATE_KEY_FILE值的方式,如字符串,纯文本等。
在错误之前将我的凭据记录在行上(我肯定错过了一个令牌)
创建新的服务帐户并再次执行密钥创建步骤
运行curl“https:// metadata / computeMetadata / v1 / instance / service-accounts / default / token”-D“Metadata-Flavor:Google”获取更多信息。
that command gives me this:
那个命令给了我这个:
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
so I'm definitely missing a token, but for some reason I cannot figure out how I am supposed to be getting it. Or where I need to store it when my app is deployed and wants to access the API online. It feels like this should be a really easy thing to find, but for some reason all the documentation I'm reading is leading me into walls. Any help would be awesome.
所以我肯定错过了一个令牌,但由于某种原因,我无法弄清楚我应该如何得到它。或者在部署我的应用程序并希望在线访问API时我需要存储它。感觉这应该是一个非常容易找到的东西,但由于某种原因,我正在阅读的所有文档都引导我进入墙壁。任何帮助都是极好的。
1 个解决方案
#1
2
If your code is running on a Google Compute Instance, and the instance has the correct scopes, you don't need to set any environment variables.
如果您的代码在Google Compute Instance上运行,并且实例具有正确的范围,则无需设置任何环境变量。
You can confirm the scopes by looking at the instance in the Developers Console or by asking the metadata server:
您可以通过查看Developers Console中的实例或询问元数据服务器来确认范围:
curl https://metadata/computeMetadata/v1/instance/service-accounts/default/scopes -H "Metadata-Flavor: Google"
To use Cloud Datastore, both the datastore
and userinfo.email
scopes must be present.
要使用Cloud Datastore,必须同时存在数据存储区和userinfo.email范围。