简体   繁体   English

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

[英]Google Datastore access using Service Account Keys

I have a GCD account within which i created a project and datastore within the latter. 我有一个GCD帐户,我在其中创建了一个项目和数据存储。 I downloaded the service account keys for this project and stored in my local PC. 我下载了该项目的服务帐户密钥,并将其存储在本地PC中。

Now, i have a simple node app running in my PC. 现在,我在PC上运行了一个简单的节点应用程序。 This node app has a simple query to fetch data from google datastore created above. 此节点应用程序具有一个简单的查询,可从上面创建的Google数据存储区中获取数据。 All i need to know is how should i configure the service account keys in my node app to gain access to datastore and the corresponding entities because i get an error like this when i try to access - "Missing or insufficient permissions." 我所需要知道的是,我应该如何在节点应用程序中配置服务帐户密钥以访问数据存储区和相应的实体,因为在尝试访问时出现这样的错误-“缺少权限或权限不足”。

Node app query - 节点应用查询-

// 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);

To use Service Account credentials change your client code to: 要使用服务帐户凭据,请将您的客户端代码更改为:

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

You must create a Datastore Emulator. 您必须创建一个数据存储模拟器。

Please follow the steps bellow. 请按照下面的步骤。

gcloud components install cloud-datastore-emulator

gcloud beta emulators datastore start

oiutput: [datastore] Dev App Server is now running. oiutput:[数据存储] Dev App Server现在正在运行。

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

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

相关问题 在前端访问Google Cloud Datastore密钥 - Access google cloud datastore keys on the frontend Google Directory API:无法使用服务帐户访问用户/组端点 (403) - Google Directory API: Unable to access User/Group endpoints using Service Account (403) 使用服务帐户通过 Google API 进行授权 - Authorizing with Google APIs using a service account 如何通过 Google 数据存储中的嵌套键进行查询? - How to query through nested keys in Google datastore? 使用服务帐户访问Google Container构建器日志 - 403 Forbidden Error - Access Google Container builder logs with a service account - 403 Forbidden Error google api服务帐户访问用户任务列表 - google api service account Access user task list Google API服务帐户 - 无法访问私人数据 - Google API Service Account - Can't Access Private Data 通过服务帐户访问 Google Drive:错误:需要登录 - Access to Google Drive through Service Account : Error: Login Required 使用服务帐户的 Google 目录 API - 错误自签名证书 - Google directory API using Service account - error self signed cert 如何使用Node.js为Google服务帐户创建JWT? - How to create JWT for Google service account using Node.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM