This is a very basic HOWTO on retrieving a particular item in a Google Docs spreadsheet from your blog (not necessarily Tumblr), something that I could have used a few days ago. I use this over at my scifaiku site to show author notes for particular posts. *
- Create a new spreadsheet
- Use the first row to label the fields
- Enter some data
- Publish the spreadsheet
- Go to More publishing options
- Select RSS from the File format dropdown
- Click Generate URL and copy the resulting URL
- Modify the URL from something like
http://spreadsheets.google.com/feeds/list/
o<numbers>.<numbers>/od6/public/basic?alt=rss
to something like (one line)http://spreadsheets.google.com/feeds/list/
o<numbers>.<numbers>/od6/public/basic?
alt=json-in-script&callback=notesLoaded&sq=postid%3D{PostID}
where sq is a structured query (in this case, the postid field must be equal to the current Tumblr post id) - Create a JSON call using the above URL, and put this near </body> (one line):
<script src="http://spreadsheets.google.com/feeds/list/
o<numbers>.<numbers>/od6/public/basic?
alt=json-in-script&callback=notesLoaded&sq=postid%3D{PostID}" type="text/javascript"></script> - Specify an output location using a named div
<div id="authnotes_load"></div>
If you want a nice "loading" animation to put inside this div, get one from ajaxload.info - Write the callback handler:
function notesLoaded(obj) {
var notediv = document.getElementById('authnotes_load');
if(typeof(obj['feed']['entry']) != 'undefined') {
// 10 length of 'authnote: ', the first column
var note =
obj['feed']['entry'][0]['content']['$t'].substring(10);
notediv.innerHTML = "<p><span>author's notes :"
+ "</span> " + note + "</p>";
} else
notediv.innerHTML = '';
}
Adjust the above to taste. Enjoy!
You can see this in action here. A modified version is used at the main scifAI page ("42").
* Update: Deprecated in favor of just using Disqus comments.
1 comment:
RSS is not included in the file format dropdown anymore?
Post a Comment