0

Currently I'm generating a Google Documents file through the Drive API using the Java client. This works fine, and as credentials we're using a service account. After the document is created, the account shares it with the e-mail of the logged in user. So far, so good.

The second part was to generate headers and other content for this new empty document. We discovered that scripts can be deployed as API executables + triggered via the "scripts execution API", but bumping into:

Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
"The caller does not have permission"

From other threads & topics that I've found, it ranges from "it won't work with service accounts to associating the project correctly", what I've tried:

-> Created a bound script to a document, deployed as API, changed the project number to the one for which the service account is also owner

-> Enabled the Drive API's + Script API

-> Provided the following scopes:

DriveScopes.DRIVE_FILE, ScriptScopes.DRIVE, "https://www.googleapis.com/auth/documents"

(The last scope was one visible in the Project properties of the script.

I've tried this process for bound scripts & standalone ones, each time associating them with the project, everytime I get the same error.

It's pretty vital that this works server to server, so I cannot have any user interaction, as it has to generate reports & fill them with some standard structure + having an "easy...." way to validate the structure afterwards.

Busata
  • 1,088
  • 1
  • 10
  • 24

1 Answers1

0

One reason that you got this forbidden error is because of the wrong/incomplete scope that you are using. So make sure that you use proper scope in your application. You can verify it by checking the answer in this SO question.

I also found out that there is a known bug that Execution API - can't be use a service account. So just check the alternative solution for this issue.

For more information, check these threads if it can help you.

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31