简体   繁体   English

Node.js和Google Cloud数据存储入门教程中的令牌错误

[英]Token error on getting started tutorial with Node.js and Google Cloud datastore

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 . 我正在使用Google Appengine,node.js和socket.io构建一个Webapp,目前正在按照本教程尝试设置一个Google计算实例,以使用Google Cloud Datastore API。 So far, I've completed steps 1 and 2, but when running the downloaded adams.js file locally, I get this: 到目前为止,我已经完成了步骤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) gcloud auth登录(这将我登录到Google,但未在本地设置我的令牌)
  • changing the way I'm exporting my DATASTORE_SERVICE_ACCOUNT and DATASTORE_PRIVATE_KEY_FILE values, as strings, plain text, etc. 更改我将DATASTORE_SERVICE_ACCOUNT和DATASTORE_PRIVATE_KEY_FILE值导出为字符串,纯文本等的方式。
  • 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 " http://metadata/computeMetadata/v1/instance/service-accounts/default/token " -D "Metadata-Flavor: Google" to get more info. 运行curl“ http:// 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. 或在部署我的应用程序并希望在线访问API时需要在哪里存储它。 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. 任何帮助都是极好的。

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实例上运行,并且实例具有正确的作用域,则无需设置任何环境变量。

You can confirm the scopes by looking at the instance in the Developers Console or by asking the metadata server: 您可以通过在开发人员控制台中查看实例或询问元数据服务器来确认范围:

curl http://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,必须同时存在datastoreuserinfo.email范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM