I followed the tutorial on https://developers.google.com/identity/protocols/application-default-credentials to use the default credentials in my application on the google app engine. However, when running the app locally, I get a 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 is the code I use, included the parts of tutorial:
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.force-ssl");
try{
// Authorize the request.
GoogleCredential credential = GoogleCredential.getApplicationDefault();
if (credential.createScopedRequired()) {
credential = credential.createScoped(scopes);
}
// This object is used to 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 the Google Cloud SDK installed, I used the shell to give permission to get access to my google account
There are several steps that you need to follow in order to use the application default credentials... You can follow the steps below, or have a look at this link.
Commands to configure system variables...
After you authenticate, and authorize yourself, you can then start using the applications default credentials, given that you have setup your environment properly.