I created a GAS and deployed it as google web app. it is available with https://script.google.com/macros/s/..../exec URL. Now I want to run it from Java servlet. I created application in console.developers.google.com, created CLIENT ID for Service account and API KEY and private key file.
Now I'm trying to run script as follows:
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
// Build service account credential.
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("[email protected]")
.setServiceAccountScopes(Collections.singleton("https://script.google.com"))
.setServiceAccountPrivateKeyFromP12File(new File(getClass().getClassLoader().getResource("key/eForms-055a7029cd36.p12").toURI()).getAbsoluteFile())
.build();
// Set up and execute a Google Cloud Storage request.
String URI = "https://script.google.com/macros/s/.../exec?payload="+form.toString();
HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
GenericUrl url = new GenericUrl(URI);
HttpRequest http_request = requestFactory.buildGetRequest(url);
HttpResponse response = http_request.execute();
String content = response.parseAsString();
And I get
com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
"error" : "invalid_grant"
}
I think that I set wrong slot, but which one to set?