Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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(); 
like image 700
Hemant Yadav Avatar asked Jun 18 '16 05:06

Hemant Yadav


People also ask

What is a range in Google Sheets?

A range can be a single cell in a sheet or a group of adjacent cells in a sheet.

Can Google Sheets pull data from an API?

Once you've set up your API to Google Sheets connection, click Save And Run to get data to your spreadsheet.


2 Answers

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

like image 106
ritesh.garg Avatar answered Sep 18 '22 14:09

ritesh.garg


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";

like image 20
Boom3k Avatar answered Sep 17 '22 14:09

Boom3k