Datastore auth error

68 views
Skip to first unread message

Prakash Natarajan

unread,
Oct 17, 2017, 9:50:01 AM10/17/17
to google-appengine-go
Hi,

  I have tried connect datastore with appengine in golang, but getting an error about authentication in my local by using GoogleCloudSdk/bin/dev_appserver.py datastore/app.yaml. Please some one help me to solve this problem.


app.yaml

runtime: go
api_version: go1

handlers:
- url: /.*
  script: _go_app

env_variables:
  GCLOUD_DATASET_ID: "abc-1234567"


datastore.go

package gaedatastore

import (
           "log"
           "net/http"
           "os"
           "encoding/json"
           "cloud.google.com/go/datastore"
           "google.golang.org/appengine"
)

var datastoreClient *datastore.Client

func init() {

   http.HandleFunc("/articles", articlesListB)

}

func articlesListB(res http.ResponseWriter, req *http.Request) {
  ctx := appengine.NewContext(req)
  projectID := os.Getenv("GCLOUD_DATASET_ID")
  var err error
  datastoreClient, err = datastore.NewClient(ctx, projectID)
  if err != nil {
    log.Fatal(err)
  }
  query := datastore.NewQuery("Article").Order("Title").Limit(10)
  articles := make([]*Article, 0)
  _, err = datastoreClient.GetAll(ctx, query, &articles)
  if err != nil {
      http.Error(res, err.Error(), http.StatusInternalServerError)
      return
        }
  json.NewEncoder(res).Encode(articles)
}







Thanks,
Prakash.N


Prakash Natarajan

unread,
Oct 17, 2017, 9:51:03 AM10/17/17
to google-appengine-go
Error:


rpc error: code = Unauthenticated desc = Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages