1
votes

I tried a simple Java command-line application that makes requests to the Google Apps Script Execution API. Something like this: https://developers.google.com/apps-script/guides/rest/quickstart/java#prerequisites. But it doesn't work.

Google Apps Script Editor:

function createForm() {

  var form = FormApp.create('New Form');

}

Java Error:

Credentials saved to /home/palmaslab/.credentials/script-java-quickstart.json
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
        at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
        at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
        at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
        at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
        at org.gradle.AppsScriptApiQuickstart.main(AppsScriptApiQuickstart.java:188)
2
we cant help if you dont show us the java code. Also tell us how you configured the script for execution api.Zig Mandel

2 Answers

0
votes

Seems you have to authorize previously the scopes. Maybe it could help you: Manual authorization scopes for Sheets, Docs, and Forms

1
votes

API returning an HTTP 401 response when calling the API. These error could indicate any of:

Token expiry, token revocation, token not authorized for needed scope, request not authorized correctly with OAuth 2.0 protocol. You may also check Forms Service for more information regarding forms services

Here's a related issue of 401: Unauthorized: Google apps script and execution API: latest version of script throws error