Retrieving JSON Data From a Private Google Spreadsheet - json

I have searched high and low, but I cannot find an answer to my question.
Is it possible to retrieve data from a private Google spreadsheet in JSON format using php?
I know how to authenticate to access the spreadsheet.
When I use this url: https://spreadsheets.google.com/feeds/list/$key/od6/private/full
I get results in xml, but when I try to add "?alt=json" no content is returned.
Is it possible to get the results returned as JSON?

One workaround is to use as a gateway between your GSheet and a custom JSON web API such as: https://apispark.com/docs/tutorials/google-spreadsheet

Related

Google Sheets - UrlFetchApp/ GetContentText - working with data?

I have managed to receive HTTP response from a protected webpage by using UrlFetchApp and passing credentials/cookie etc. This correctly returns the data and I have been able to convert to a blob and download as a text file.
However, what I want to do is extract the relevant table from the HTML file, in exactly the same way as the ImportHTML() function works in google sheets. Can anyone give me some hints on this? I have tried parsing using xml service but it doesn't like the data, i'm hoping there is a simpler way?
Cheers

Google Spreadsheets retrieving JSON feed

I recently started using the "New Google Sheets" (spreadsheets) and they changed the URL to a shared public spreadsheet and I am unsure how to obtain a JSON feed of the spreadsheet data.
Based on data from this URL: https://developers.google.com/gdata/samples/spreadsheet_sample
I can obtain the JSON data from an older version spreadsheet using the key parameter found in a URL of this format: http://spreadsheets.google.com/feeds/feed/key/worksheet/public/basic?alt=json-in-script&callback=myFunc
However, the new sheets have a URL like this:
https://docs.google.com/spreadsheets/d/SOME-IDENTIFIER/pubhtml
Using "SOME-IDENTIFIER" in place of the key does not work, I'm not sure how I can pull the JSON feed from a new spreadsheet... Anyone have any experience with this?
The format you should use is this :
https://spreadsheets.google.com/feeds/cells/
SHEET-IDENTIFIER/
SHEET_INDEX/
public/basic?alt=json-in-script&callback=JSON_CALLBACK
You can find SHEET_INDEX by looking at the end of the URL while editing the sheet.
...SHEET-IDENTIFIER/edit#gid=SHEET_INDEX
Make sure the spreadsheet is published (not only shared).
File/Pulish to the web...
I tried Vlad's answer and it didn't work; the editing url had gid=0, but in order to get the feed I wanted I had to put in 1 as the sheet index.

Twitter JSON to Google Spreadsheet API - 1. importing and reading JSON files

I'm trying to link Google Spreadsheet to twitter- have them talk to eachother - and I'm trying to use JSON.
(Trello and Google calendar are another idea with JSON)
from what I've gathered, you're supposed to use Utilities.JSONParse() for this data. I'm not sure what goes in the brackets to create a JSON object. I keep getting an invalid JSON string when my basic code runs;
function myFunction() {
var j = UrlFetchApp.fetch("https://api.trello.com/1/organizations/fogcreek?key=727f13bf79cfa362db49b79eb8c56c94");
Utilities.jsonParse(j);
}
So... examples/help on how to read JSON objects in a google spreadsheet would be great!
Thanks.
This is a Google Docs spreadsheet a very clever guy has created which imports from Trello using Google Apps script:
http://www.littlebluemonkey.com/blog/online-scrum-tools-part-4-trello-backup/
It takes the JSON data and translates it, so looking at his code may help you with twitter json import.
There's also another clever guy who explains how he's done something similar with Trello:
http://www.kevinpelgrims.com/blog/2012/03/05/project-progress-tracking-with-google-docs-and-trello/

JSON response is bloated for API requests to Google Sheets

I'm using the spreadsheet JSON api on a public read-only document. Is there a way to not receive the links of the individual cells and all the extra bloat? I just want the data.
My request is constructed as
http://spreadsheets.google.com/feeds/list/DOCKEY/public/values?alt=json-in-script&callback=callback
Eliminating the category and link objects would vastly shrink the response..
I could use basic instead of values, but then I would have to parse the content.$t. to get the values....
Is there another way I'm not finding?
Thanks.
You might consider using Apps Script, which will provide you with methods to retrieve the values of the cell range you specify:
https://developers.google.com/apps-script/class_range#getValues
You might consider downloading the spreadsheet in csv format. There does not seem to be an API for that, but maybe you could build the URL yourself.
See also Using the google drive API to download a spreadsheet in csv format
Similar to the Apps Script SpreadsheetApp#Range#getValues() is the Sheets REST API's spreadsheets.values() endpoint. The benefit here is that you can deploy this from a location of your choosing, and are not confined to working in the Apps Script version of Javascript. Client libraries which simplify the implementation of authorized access are available from Google in a number of languages.
Additionally, when making requests to Google REST APIs, one of the Standard Parameters is the fields specification, which allows limiting the data that should be returned to only that which you request be sent.
To quote their partial response snippet:
Spreadsheets are big, and often you don't need every part of the spreadsheet. You can limit what's returned in a Google Sheets API response, using the fields URL parameter. This is especially useful in the spreadsheets.get method. For best performance, explicitly list only the fields you need in the reply. The format of the fields parameter is the same as the JSON encoding of a FieldMask. In a nutshell, multiple different fields are comma separated, and subfields are dot-separated. For convenience, multiple subfields from the same type can be listed within parentheses.
For example, to retrieve the spreadsheet's title, the sheet's properties, and the value and format of range A1:C10. you could use the following request:
GET https://sheets.googleapis.com/v4/spreadsheets/YOURSHEETID?ranges=A1:C10&fields=properties.title,sheets(sheetProperties,data.rowData.values(effectiveValue,effectiveFormat))

How do you retrieve data from a Google Docs Spreadsheet?

I found this wonderful example of pulling data from a Google spreadsheet in JSON:
http://code.google.com/apis/gdata/samples/spreadsheet_sample.html
However, I can't seem to get it to work for a spreadsheet I created. I've made the doc public and published it, and tried every possible tweak on the key and sheet "name". Has anyone successfully used this? I've seen the Zend GData library, but would rather use JSON.
Thanks in advance for any tips.
I tried to work with the JSON feed a few months ago and I remember having to jiggle the handle a little to get the feed URL to work. I don't recall exactly what I did, but the bigger problem is that once you get it working the feed itself is kind of a mess.
I found that a much better solution (for my purposes, at least) was to use the CSV feed and then convert that to JSON on the server. I actually wrote a blog post outlining the steps a few weeks ago:
http://www.ravelrumba.com/blog/json-google-spreadsheets/
Google Spreadsheet as JSON can be done using Google Apps Script !
In Google Spreadsheet go to Tools > Scripts > Script Editor
Insert this code and hit the play button, use generated URL for generating JSON.
function getValues() {
var range = SpreadsheetApp.getActiveSheet().getDataRange();
var json = Utilities.jsonStringify(range.getValues())
Browser.msgBox(json);
}​
also give it a try for Simple example of retrieving JSON feeds from Spreadsheets Data API