Accessing a (new-style, public) Google sheet as JSON

后端 未结 5 1743
臣服心动
臣服心动 2020-12-04 08:41

How can I access the contents of a (new-style) Google sheet a JSON? My aim is to access the values from JavaScript, so I need to be able to download the JSON via HTTP.

5条回答
  •  盖世英雄少女心
    2020-12-04 08:52

    A faster solution here is to use this https://gist.github.com/ronaldsmartin/47f5239ab1834c47088e to wrap around your existing spreadsheet.

    You first need to change your sheet access to Anyone with link can View

    Add the id and sheet html param to the URL below.

    https://script.google.com/macros/s/AKfycbzGvKKUIaqsMuCj7-A2YRhR-f7GZjl4kSxSN1YyLkS01_CfiyE/exec

    Eg: your id is your sheet id which is

    1mhv1lpzufTruZhzrY-ms0ciDVKYiFJLWCMpi4OOuqvI

    and your sheet which is

    Sheet2

    In your case you can actually see your data here as json at

    https://script.google.com/macros/s/AKfycbzGvKKUIaqsMuCj7-A2YRhR-f7GZjl4kSxSN1YyLkS01_CfiyE/exec?id=1mhv1lpzufTruZhzrY-ms0ciDVKYiFJLWCMpi4OOuqvI&sheet=Sheet2

    To be safe, you should deploy the code sheetAsJson.gs in the github gist above as your own in your Google Drive.

提交回复
热议问题