Skip to content

Instantly share code, notes, and snippets.

@jasonclark
Last active May 4, 2020 00:11
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save jasonclark/2585071 to your computer and use it in GitHub Desktop.
Save jasonclark/2585071 to your computer and use it in GitHub Desktop.
booklist javascript (jQuery) - calling google spreadsheet api, parsing response
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
//source Google Sheets file is https://docs.google.com/spreadsheets/d/1rX4_fInsYS7vOGpnXm1UklZgvU27FXl3UYu9lx9RHHU/
$(function listBooks() {
$.getJSON( "https://spreadsheets.google.com/feeds/list/1rX4_fInsYS7vOGpnXm1UklZgvU27FXl3UYu9lx9RHHU/1/public/full?alt=json",
function (data) {
$('div#book-list').append('<ul class="items"></ul>');
$.each(data.feed.entry, function(i,entry) {
var item = '<span style="display:none">' + entry.id.$t + '</span>';
item += '<img src="https://covers.openlibrary.org/b/isbn/' + entry.gsx$isbn.$t + '-S.jpg"/>';
item += '<span class="meta"><a href="https://www.worldcat.org/isbn/' + entry.gsx$isbn.$t + '">' + entry.title.$t + '</a>';
item += '<br/>Author: ' + entry.gsx$author.$t;
if (entry.gsx$notes.$t) {
item += '<br/>Description: ' + entry.gsx$notes.$t;
}
$('.items').append('<li>' + item + '</span></li>');
});
});
});
});
</script>
@WhatLibrarian
Copy link

I'm not sure you would be able to use a non-public spreadsheet as the functions rely on generated RSS/ATOM feeds from a published sheet. More information about the Google Spreadsheet API can be found at https://developers.google.com/google-apps/spreadsheets/ but from what I'm reading there you will need to 'publish to web' to make this work. Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment