0

using REST Reference in node js Google cloud store I got this error in the postman i got the following error. URL: https://datastore.googleapis.com/v1/projects/{projectId}:allocateIds Requset Body:

 {
"keys": [
{
  "partitionId": {
    "namespaceId": "default",
    "projectId": "superb-watch-172816"
  },
  "path": [
    {
      "kind": "User50records"
    }
  ]
}
]}

I got this error:

{ "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED" } }

1 Answers1

1

Truly anonymous calls to Cloud Datastore aren't allowed. You must identify yourself to the server in some manner. The bare minimum is attaching an API key, which is basically a claim that you are associated with some project or other. If you're accessing data that is not publicly viewable by anyone, you'll also need to provide some sort of authentication, which is usually done via OAuth.

So, minimum amount of work, assuming this is public data: get an API key, and then append a "key=myKey" query parameter to your URL.

Auth guide: https://cloud.google.com/docs/authentication/

Brandon Yarbrough
  • 37,021
  • 23
  • 116
  • 145
  • 1
    Just wanted to addthatin order to use GCS through the API, if you are not using either Google Compute Engine or Google App Engine. It is necessary to create a service account and from there you can download the key in XML or JSON. If you are using GAE or GCE, it is possible to just create the API Key as Brandon stated or use the default credentials of the service. – Nilo_DS Aug 02 '17 at 16:40
  • 1
    @VinodKumarMarupu - it is likely that you need to provide authentication. A quick way to test this would be to use the gcloud tool. Run `gcloud auth print-access-token`. Put the results into a request header like "Authorization: Bearer ya29.whateverxxxxxxxxxxxxxxxxxxxxxxx" – Brandon Yarbrough Aug 02 '17 at 17:22
  • @BrandonYarbrough got it worked for me, And While running https://datastore.googleapis.com/v1/projects/xxx:runQuery api I got data { "batch": { "entityResultType": "PROJECTION", "endCursor": "CgA=", "moreResults": "NO_MORE_RESULTS" } } how to see actual data from entity? – Vinod Kumar Marupu Aug 02 '17 at 17:43
  • @Nilo_DS is correct. You'll need to setup a service account from your Google API Console and use its credentials to authenticate with the Cloud Datastore REST API. Here's a link to a guide on setting up service accounts: https://developers.google.com/identity/protocols/OAuth2ServiceAccount – TheAddonDepot Aug 04 '17 at 11:20
  • @BrandonYarbrough Can you please help out here https://stackoverflow.com/questions/45553555/datastore-queries-to-retrive-multiple-values-in-gcp-nodejs – Vinod Kumar Marupu Aug 07 '17 at 19:14