如何阅读使用google api公开使用Java的电子表格?

时间:2018-01-22 15:51:21

标签: java google-sheets google-drive-api spreadsheet

我想阅读pubhtml中公开的spreadsheet之一的数据。

如何使用google-api阅读上面的电子表格?

我已经尝试了以下步骤,但收到错误:

  1. 我将google API doc与我的电子表格ID一起使用。

  2. 示例:

  3. sheet-id- 2PACX-1vTe-
    Cmpii1CsnufmSER7ObEuhBb4TGO29RRwcEAQjW8PYkHKQMfUvriPk2LPXyCm8HMKCIvNFXSqJkU
    
    1. 错误:
    2. Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
      {
        "code" : 404,
        "errors" : [ {
          "domain" : "global",
          "message" : "Requested entity was not found.",
          "reason" : "notFound"
        } ],
        "message" : "Requested entity was not found.",
        "status" : "NOT_FOUND"
      }
          at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
          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:1065)
          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 Quickstart.main(Quickstart.java:108)
      
      Process finished with exit code 1
      
      

      有谁知道错误是什么?

1 个答案:

答案 0 :(得分:0)

确保您提供正确的spreadsheetID。错误意味着找不到扩展表。

您可以使用此spreadsheets.values.get Try-it来验证。如果它发出相同的错误,则表示您需要重新检查spreadsheetID

这是spreadsheetID的样子:

https://docs.google.com/spreadsheets/d/1qpyC0XzvTcKT6EISywvqESX3A0MwQoFDE8p-Bll4hps/edit#gid=0

<强> spreadsheetID

  

1qpyC0XzvTcKT6EISywvqESX3A0MwQoFDE8p-Bll4hps