Google spreadsheet API, 400 error bad request : unable to parse range

与世无争的帅哥 提交于 2019-11-26 20:19:11

问题


I am trying to access Google spreadsheets using a spreadsheet example. When I run the example code it worked fine. I just change the SpreadsheetId and range. It started giving me:

Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Unable to parse range: Class Data!A2:A4",
    "reason" : "badRequest"
  } ],
  "message" : "Unable to parse range: Class Data!A2:A4",
  "status" : "INVALID_ARGUMENT"
}
    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 poc.mainPOC.main(mainPOC.java:157)

Below is the code:

  String spreadsheetId = "my spread sheet ID";
    String range = "Class Data!A2:A4";
    ValueRange response = service.spreadsheets().values()
        .get(spreadsheetId, range)
        .execute();

回答1:


Try replacing Class Data!A2:A4 with A2:A4




回答2:


If you look at the sheet itself you will notice that the Worksheet is titled "Class Data". So just put the name of your sheet where is says "Class Data". Example: String range = "SheetName!A1:C";




回答3:


I was trying to add some data to a sheet named Emmett that did not existed yet and was receiving this error:

Error: Unable to parse range: Emmet!A2:C12

I had to manually create the sheet named Emmett in the spreadsheet and then it worked like a charm.




回答4:


I ran into this error when I had a typo in the name of the tab. In your case "Class Data" didn't match the name of the tab




回答5:


String range = "Class Data!A2:A4";

The Class Data is your worksheet's name, FYI: the name on the tab at the bottom, the default one is "Sheet1". Replace Class Data with the one you want to work with.



来源:https://stackoverflow.com/questions/37893515/google-spreadsheet-api-400-error-bad-request-unable-to-parse-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!