Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

javascript - Google Docs Spreadsheet to JSON

I've seen numerous articles on this but they seem outdated, for instance none of the Google Docs Spreadsheet urls has key parameter. I read this as well: JSON data from google spreadsheet

Then I read this to access data https://developers.google.com/gdata/samples/spreadsheet_sample

My spreadsheet exists at: https://docs.google.com/spreadsheets/d/1SKI5773_68HiSve1fsz7fr4gotjFWHB7KBuVsOlLz6I/edit#gid=0

I've tried using this code, I think I have a problem with the key or syntax, please guide to fix.

<script src="http://spreadsheets.google.com/feeds/feed/1SKI5773_68HiSve1fsz7fr4gotjFWHB7KBuVsOlLz6I/worksheet/public/basic?alt=json-in-script&callback=importGSS"></script>

<script type="text/javascript">

    function importGSS(json) {
        console.log('finished');
    }
</script>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The src attribute in your script tag is an invalid link (and you can see this for yourself by viewing your link directly in a browser).

The feed/key/worksheet section of the URL has the right key but the wrong feed and worksheet.

In the URL, replace "feed" with either "cells" (separate value for each cell) or "list" (separate value for each row).

At the same time, replace "worksheet" with "od6" (indicating the leftmost, or default, sheet - see this blog post for accessing other sheets).

If you view this new URL directly in a browser, you can see that it returns a meaningful value.

Your final script tag might look like this:

<script src="https://spreadsheets.google.com/feeds/list/1SKI5773_68HiSve1fsz7fr4gotjFWHB7KBuVsOlLz6I/od6/public/values?alt=json-in-script&callback=importGSS"></script>

For more info, you can see an example on the Google Developers site


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...