google sheet api v4是否支持"Google Application Default Crentials"?

Cre*_*ent 5 google-sheets-api

我在我的scala应用程序中使用"Google Application Default Credentials"来与google sheet api交谈.但是,我从api响应中收到"PERMISSION_DENIED"错误消息.

这是我的代码片段:

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
Run Code Online (Sandbox Code Playgroud)

这是错误消息:

com.google.api.client.googleapis.json.GoogleJsonResponseException:403 Forbidden {"code":403,"errors":[{"domain":"global","message":"请求的身份验证范围不足.", "reason":"forbidden"}],"message":"请求的身份验证范围不足.","status":"PERMISSION_DENIED"}

我在google开发者控制台中启用了google sheet api,而我正在尝试阅读的工作表位于我的google驱动器下.

我唯一不确定的是google sheet api doc https://developers.google.com/sheets/guides/authorizing#OAuth2Authorizing没有提及api是否支持"Google Application Default Credentials".

我在这里可能会错过或做错的事吗?