How do you retrieve data from a Google Docs Spreadsheet? - json

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

Related

Why am I receiving "Could not fetch URL" error on Google Sheets Import XML?

New here, and still trying to wrap my mind around this importXML tool in Google Sheets. Seem to be able to get it to work on certain websites, but when data is deeply embedded in code, I struggle.
Goal: To pull in weight of items listed on bricklink.com to a Google Sheet.
Link to my Google Sheet: https://docs.google.com/spreadsheets/d/1_vhCkEJXofxMj1Cg117RgPJSFTqPF0ijo_f60mDR6MU/edit?usp=sharing
When I copy the xpath from the source code on the site, I'm given this value: //*[#id="item-weight-info"].
The existing fomula I have is: =IMPORTXML(D2,"//*[#id='item-weight-info']")
D2 Contains the web address where it concatenates the website + the item number.
Error I'm receiving is: "Could not fetch url: https://www.bricklink.com/v2/catalog/catalogitem.page?S=21318"
I did come across a potential JSON solution, set up a JSON function in the sheet, but have never written a script before. Tried to copy a script, and tweak as needed, but still no luck.
Is there an easier way to do this that I'm overlooking?
Any guidance or suggestions would be greatly appreciated. Thank you for your time!

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

IMPORTxml on google sheets

Trying to make a spreadsheet on google sheets that scrapes data from a site.
I'm trying to get the sell price of items from rsbuddy exchange, eg:
https://rsbuddy.com/exchange/?id=1745
I have the code on google sheets as:
=IMPORTxml("https://rsbuddy.com/exchange/?id=1745","//*[#id='sell-price']")
But instead of showing me 1734gp it comes up as --- on the sheet.
I've tried adding /text() at the end of the query for the importxml but it doesn't change anything.
I'm guessing the solution is something similar?
I don't believe you can do it with xpath because it's populated dynamically. If you view the full source, you're getting what is there. It's literally ---
You can see the source data here which is in JSON and looks like it's tied to the page url id. Google sheets doesn't natively support json but this good person wrote a script and it seems to work well in my example sheet.
You'll need to do it via JSON, though you can't importJSON natively through Google Sheets. If you add this library as code to your sheet (via the script editor) then you can you can use =IMPORTJSON (with different parameters) to get the data back that you need.
http://blog.fastfedora.com/projects/import-json

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/