java - Default Credentials in Google App Engine: Invalid Credentials error -


i followed tutorial on https://developers.google.com/identity/protocols/application-default-credentials use default credentials in application on google app engine. however, when running app locally, 401 error (invalid credentials)

com.google.api.client.googleapis.json.googlejsonresponseexception: 401 ok { "code" : 401, "errors" : [ { "domain" : "global", "location" : "authorization", "locationtype" : "header", "message" : "invalid credentials", "reason" : "autherror" } ], "message" : "invalid credentials" }

this code use, included parts of tutorial:

list<string> scopes = lists.newarraylist("https://www.googleapis.com/auth/youtube.force-ssl");         try{             // authorize request.             googlecredential credential = googlecredential.getapplicationdefault();              if (credential.createscopedrequired()) {                 credential = credential.createscoped(scopes);                }             // object used make youtube data api requests.             youtube = new youtube.builder(auth.http_transport, auth.json_factory, credential)                     .setapplicationname("youtube-cmdline-captions-sample").build();         } catch (ioexception e) {             e.printstacktrace();         } 

i have google cloud sdk installed, used shell give permission access google account

there several steps need follow in order use application default credentials... can follow steps below, or have @ link.

  1. first things first : install google cloud storage sdk
  2. make sure can run commands sdk. if not have python installed need install python 2.7 or above, , pyopenssl...
  3. you need authenticate within sdk running gcloud auth activate-service-account [service account email] --key-fil e [.p12 file] . when run should message telling you have activated service account
  4. you need set environment variables sdk setting google_application_credentials json path of secret cloudsdk_python_sitepackages 1, , setting project

commands configure system variables...

 set google_application_credentials "secret.json path" set cloudsdk_python_sitepackages 1 gcloud config set project "your project name" 

after authenticate, , authorize yourself, can start using applications default credentials, given have setup environment properly.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -