Access Google-apps public spreadsheet via Javascript

前端 未结 2 1418
臣服心动
臣服心动 2020-12-29 16:14

Spent a bunch of time looking at this.. It seems that what little info there was about accessing a Google-apps spreadsheet is not very well maintained.. At Google IO this ye

相关标签:
2条回答
  • 2020-12-29 16:48

    I have implemented a fairly complete example and the code is at https://bitbucket.org/tbrander/ggadget/wiki/Home Code is BSD license (except for Trademarks and institutional markings which are all rights reserved) It is reasonably well commented... It is in operation at http://acre.cba.ua.edu/ (bottom of page) Stand alone at : http://acre.cba.ua.edu/mobiletool/res.html

    It functions across IE, Chrome FF i-Phone and Android Your hints above are close but I was looking for yet more... as You can now see,, But I will explore the Jquery syntax as the current implementation is pure JS

    0 讨论(0)
  • 2020-12-29 16:49

    Google provide a documented way to access google spreadsheet via JSONP that works for normal gmail.com accounts. In short:

    • Create a spreadsheet
    • Click on the dropdown next to "Share" and select "Publish as a web page"
    • Copy and paste out the key from the URL that shows (i.e. the bit after &key=)
    • Go to https://spreadsheets.google.com/feeds/cells/0AmHYWnFLY1F-dG1oTHQ5SS1uUzhvTnZTSHNzMjdDaVE/od6/public/values?alt=json-in-script&callback=myCallback replacing "0AmHYWnFLY1F-dG1oTHQ5SS1uUzhvTnZTSHNzMjdDaVE" with whatever key you cut out of the url

    To access this from within JavaScript you'll have to insert a HTML script tag into your document:

    <script src="https://spreadsheets.google.com/feeds/cells/0AmHYWnFLY1F-dG1oTHQ5SS1uUzhvTnZTSHNzMjdDaVE/od6/public/values?alt=json-in-script&callback=myCallback"></script>
    

    And you'll need to implement the callback function in your webpage:

    function myCallback(spreadsheetdata) {
      // do something with spreadsheet data here
      console.log(spreadsheetdata);
    }
    

    You can simplify this with jQuery:

    var url = "https://spreadsheets.google.com/feeds/cells/0AmHYWnFLY1F-dG1oTHQ5SS1uUzhvTnZTSHNzMjdDaVE/od6/public/values?alt=json-in-script&callback=?";
    $.getJSON(url,{}, function (d) { console.log(d); });
    
    0 讨论(0)
提交回复
热议问题