1

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)
1
  • we cant help if you dont show us the java code. Also tell us how you configured the script for execution api.
    – Zig Mandel
    Apr 30 '16 at 16:04
1

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.