Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google sheets api google sheets api v4是否支持;谷歌应用程序默认凭证“;?_Google Sheets Api - Fatal编程技术网

Google sheets api google sheets api v4是否支持;谷歌应用程序默认凭证“;?

Google sheets api google sheets api v4是否支持;谷歌应用程序默认凭证“;?,google-sheets-api,Google Sheets Api,我在scala应用程序中使用“Google应用程序默认凭据”与Google sheets api对话。但是,我从api响应中收到一条“PERMISSION\u DENIED”错误消息 以下是我的代码片段: private val client: Sheets = { val serviceAccountScopes = List(SheetsScopes.SPREADSHEETS_READONLY) // https://developers.google.com/identi

我在scala应用程序中使用“Google应用程序默认凭据”与Google sheets api对话。但是,我从api响应中收到一条“PERMISSION\u 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
以下是错误消息:

com.google.api.client.googleapis.json.googlejson响应异常:403 禁止{“代码”:403,“错误”:[{ “域”:“全局”, “消息”:“请求的身份验证作用域不足。”, “原因”:“禁止”}],“消息”:“请求的身份验证作用域不足。”,“状态”:“权限被拒绝” }

我确实在谷歌开发者控制台中启用了谷歌工作表api,而我试图阅读的工作表就在我的谷歌驱动器下

我唯一不确定的是google sheet api文档没有提到api是否支持“google应用程序默认凭据”


这里有什么我可能遗漏或做错的吗?

它应该支持该用例。你能确保服务帐户有权访问该电子表格吗?你知道吗?我刚刚发布了一个类似的问题,其中有一点更详细:谷歌应用程序默认凭据似乎不支持与谷歌工作表API相关的作用域(即非谷歌云作用域)。