I use the "Default credentials for a Google app" in my scala app to talk to Google api sheets. However, I get the error "PERMISSION_DENIED" from the api response.
Here is a snippet of my code:
private val client: Sheets = { val serviceAccountScopes = List(SheetsScopes.SPREADSHEETS_READONLY) // https://developers.google.com/identity/protocols/application-default-credentials val credential: GoogleCredential = GoogleCredential .getApplicationDefault() .createScoped(serviceAccountScopes.asJava) new Sheets.Builder(httpTransport, jsonFactory, credential) .setApplicationName(applicationName) .build() } val response = client.spreadsheets().values().get(spreadSheetId, "Total Cost!A2:C2").execute() val values = response.getValues
Here is the error message:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden {"code": 403, "errors": [{"domain": "global", "message": "The request had insufficient authentication areas". "reason": "forbidden"}], "message": "The request had insufficient authentication areas.", "status": "PERMISSION_DENIED"}
I enabled the google sheet api in the google developer console, and the sheet I'm trying to read is under my google drive.
The only thing I'm not sure about is the google api doc sheet https://developers.google.com/sheets/guides/authorizing#OAuth2Authorizing does not mention anything about whether the api supports the "Google app credentials by default" or not .
Anything I might have missed or did wrong?
source share