Bringing out the Big Guns

Introduction


Blogger allows you to build third-party applications that can interact with and manipulate the Blogger data (and metadata): the Blogger API.  This is what the mobile blogging apps use, for example. Since we can add Javascript to our Blogger pages, we can use the Blogger Api inside our own blog as a convenient way to gather information about our Blog,  making it easier to manipulate the data from the inside.  Of course we could always traverse the DOM on the page and extract the bits and pieces we need, but that can be tedious and subject to change without warning.

Before we use the Blogger Api to access our Blog within the blog, lets pick a couple of features that would be nice, but that Blogger doesn't provide for.  For me, that would be:
  1. Allow a summary of all the posts to be in the oldest-first order.
  2. Have a "next post" and "previous post" link on each blog entry, to make it easier to read the posts one after another.

Gathering the data

The Blogger API has several kinds of data that can be requested.  For our purposes, we only need the blog summary data: extracting the entire blog could get pretty large.  Getting the summary data is as simple as fetching the URL
  /feeds/posts/summary?alt=json-in-script&callback=some_function
which will fetch all the summary information in a Javascript object, and call our "some_function" method with the data as it's argument.  The easiest way to cause the page to run this, is to add a script tag to our current document thusly:

function fetch_feed_summary() {
   var script = document.createElement('script');
   script.src = "/feeds/posts/summary?alt=json-in-script&callback=do_stuff"
   document.body.appendChild(script);
}

and call fetch_feed_summary(). The server will fetch the data for us, and call do_stuff() for us, which we will write to sort the blog data in to a convenient format.


To Be continued...

Comments