繁体   English   中英

使用服务帐户密钥访问Google数据存储区

[英]Google Datastore access using Service Account Keys

我有一个GCD帐户,我在其中创建了一个项目和数据存储。 我下载了该项目的服务帐户密钥,并将其存储在本地PC中。

现在,我在PC上运行了一个简单的节点应用程序。 此节点应用程序具有一个简单的查询,可从上面创建的Google数据存储区中获取数据。 我所需要知道的是,我应该如何在节点应用程序中配置服务帐户密钥以访问数据存储区和相应的实体,因为在尝试访问时出现这样的错误-“缺少权限或权限不足”。

节点应用查询-

// Adding a Sample Entity
async function quickStart() {
  // Your Google Cloud Platform project ID
  const projectId = 'XXX';

  // Creates a client
  const datastore = new Datastore({
    projectId: projectId,
  });

  // The kind for the new entity
  const kind = 'xxx';
  // The name/ID for the new entity
  const name = xxxx;
  // The Cloud Datastore key for the new entity
  const sampleKey = datastore.key([kind, name]);

  const [entity] = await datastore.get(sampleKey);
  console.log(entity);
  }
quickStart().catch(console.error);

要使用服务帐户凭据,请将您的客户端代码更改为:

// Creates a client
const datastore = new Datastore({
    projectId: projectId,
    keyFilename: '/path/to/keyfile.json'
});

您必须创建一个数据存储模拟器。

请按照下面的步骤。

gcloud components install cloud-datastore-emulator

gcloud beta emulators datastore start

oiutput:[数据存储] Dev App Server现在正在运行。

更多详细信息: https : //cloud.google.com/datastore/docs/tools/datastore-emulator

暂无
暂无

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

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