How to access data from Google Data Store using Anguarjs $ Http POST request?

I tried, and below is my code, I don’t know what went wrong.

$http({
  method: 'POST',
  headers:'{"gqlQuery": {"queryString": "select * from culture" }}',
  url: 'https://datastore.googleapis.com/v1/projects/nammaooru-3630e:runQuery?fields=batch%2Cquery&key=[myapikey]'
}).then(function successCallback(response) {

  alert("Success"+response);
    // this callback will be called asynchronously
    // when the response is available
  }, function errorCallback(response) {
    alert("Error"+response);
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

Received error in angular Request **

https://datastore.googleapis.com/v1/projects/nammaooru-3630e:runQuery?fields=batch%2Cquery&key=[apikey]

Failed to load resource: the server responded with a status of 401 ()

Got an error while trying in Postman

URL : https://datastore.googleapis.com/v1/projects/nammaooru-3630e:runQuery?fields=batch%2Cquery&key=[apikey]

Method : POST 


    {
      "error": {
        "code": 401,
        "message": "The request does not have valid authentication credentials.",
        "status": "UNAUTHENTICATED"
      }
    }

But I got a response from the Google developer site

https://cloud.google.com/datastore/docs/reference/rest/v1/projects/runQuery#http-request

{
 "batch": {
  "entityResultType": "FULL",
  "entityResults": [
   {
    "entity": {
     "key": {
      "partitionId": {
       "projectId": "nammaooru-3630e"
      },
      "path": [
       {
        "kind": "culture",
        "id": "5629499534213120"
       }
      ]
     },
     "properties": {
      "types": {
       "stringValue": "",
       "excludeFromIndexes": true
      },
      "images": {
       "stringValue": "",
       "excludeFromIndexes": true
      },
      "bname": {
       "stringValue": "Kangeyam Kalai"
      },
      "date": {
       "timestampValue": "2017-01-14T12:44:56.933Z"
      },
      "title": {
       "stringValue": ""
      },
      "description": {
       "stringValue": "Coimbatore Kongu nadu region",
       "excludeFromIndexes": true
      }
     }
    },
    "cursor": "Ci8SKWoRc35uYW1tYW9vcnUtMzYzMGVyFAsSB2N1bHR1cmUYgICAgICAgAoMGAAgAA==",
    "version": "1484398012256000"
   }
  ],
  "endCursor": "Ci8SKWoRc35uYW1tYW9vcnUtMzYzMGVyFAsSB2N1bHR1cmUYgICAgICAgAoMGAAgAA==",
  "moreResults": "NO_MORE_RESULTS"
 },
 "query": {
  "kind": [
   {
    "name": "culture"
   }
  ]
 }
}
+6
source share
3 answers

angularjs, , , , . Google OAuth 2.0 ,

, api. ( , , : yourtokenhere)

0

- - chrome, "Run":

chrome --allow-file-access-from-files --disable-web-security --user-data-dir
+1

, , CORS. POSTMAN?

, .

0

Source: https://habr.com/ru/post/1014234/


All Articles