Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Did Google Sheets stop allowing json access?

I have an app that opens the json version of a spreadsheet that I've published to the web. I used the instructions on this website: https://www.freecodecamp.org/news/cjn-google-sheets-as-json-endpoint/

It's been working fine for a couple months, but today I realized that the url of my json file is no longer working since yesterday. It gives the message, "Sorry, unable to open the file at this time. Please check the address and try again." The regular link to view the spreadsheet as a webpage still works though.

Did Google drop support for this feature? Is there another way to get the data of a spreadsheet in json format through a URL? I started looking into the Google Developer API, but it was really confusing.

like image 664
Dima Avatar asked Nov 30 '25 18:11

Dima


2 Answers

You are using the JSON Alt Type variant of the Google Data protocol. This protocol is dated and appears to no longer work reliably. The GData API Directory tells:

Google Spreadsheets Data API: GData version is still live. Replaced by the Google Sheets API v4.

Google Sheets API v4 is a modern RESTful interface that is typically used with a client library to handle authentication and batch processing of data requests. If you do not want to do a full-blown client implementation, David Kutcher offers the following v4 analog for the GData JSON Alt Type, using jQuery:

GData (old version, not recommended):

var url = 'https://spreadsheets.google.com/feeds/list/' +
           spreadsheet_id + '/' + tab_ordinal + '/public/values?alt=json';
($.getJSON(url, 'callback=?')).success(function(data) {
  // ...
};

V4 (new version, recommended):

var url = 'https://sheets.googleapis.com/v4/spreadsheets/' +
           spreadsheet_id + '/values/' + tab_name +
           '?alt=json&key=' + api_key;
($.getJSON(url, 'callback=?')).success(function(data) {
  // ...
};

...where:

  • spreadsheet_id is the long string of letters and numbers in the address of the spreadsheet — it is the bit between /d/ and /edit
  • tab_ordinal is number of the sheet — the first sheet that appears in the tab bar is sheet number 1, the second one is 2, and so on
  • tab_name is the name of the sheet, i.e., the name you see in the tab bar at the bottom of the window when you have the spreadsheet open for editing
  • api_key is the API key you get from from Google Cloud Platform console

Note that the JSON output format differs between the two versions.

With the GData pattern, the spreadsheet needs to be shared as File > Share > Publish to the web.

With the V4 pattern, the spreadsheet needs to be shared as File > Share > Share with others > anyone with the link can view.

like image 127
doubleunary Avatar answered Dec 03 '25 13:12

doubleunary


As of March 2022:

If you dont want to create a key you can use this URL format:

https://docs.google.com/spreadsheets/d/{spreadsheetId}/gviz/tq

which downloads a json.txt file of the format

google.visualization.Query.setResponse({json});

From that you would have to slice out the json

-OR --

Just configure a key as per the Official docs.

  1. Go to Google Console and create a project (or use an existing one)
  2. Goto Credenetials page and create a API Key
  3. Include Sheets API from library
  4. And Voila!

You can now get json using URL Format:

https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/{sheetName}?alt=json&key={theKey}

Edit: The Sheet should be public and Anyone with link can view

like image 42
A5H1Q Avatar answered Dec 03 '25 13:12

A5H1Q



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!