Search code examples
apirestgdata-apibloggerblogspot

Retrieving published (non draft) blog posts from Blogger API


I'm building a website that uses the Blogger API to display blog posts inside the site instead of linking to the xyz.blogspot.com url. I can successfully grab posts via jQuery but am having trouble filtering the results based on whether or not the post is actually published (viewable on xyz.blogspot.com).

I've tried the "published-min" and "published-max" query parameters but they still return posts that are categorized as "drafts" in the blogger admin interface.

The goal is to build a paging system that shows one post at a time and doesn't have to retrieve every post on every page load in order to know if the post that comes after the current one is published or is still a draft.


Solution

  • Accessing the Blogger api via jQuery only returns published blog posts as long as you are not logged into the Blogger admin panel in the same browser on a different tab.

    Logging into the Blogger admin panel on another tab will return both draft and published posts from the same jQuery ajax request:

         $.ajax({
           type: "GET",
           url: "http://www.blogger.com/feeds/{blogger blog id}/posts/summary?alt=json",
           dataType: "jsonp",
           success: function(blogData) {
    
            var totalPosts = 0;
    
            if(blogData.feed.openSearch$totalResults)
                totalPosts = parseInt(blogData.feed.openSearch$totalResults.$t);
    
            alert(totalPosts);
    
        }
         });