Saturday, May 19, 2012

BlogSpot Feeds

What are those special feed URLs for BlogSpot? How can they be sorted, filtered? Blogs, Posts, Comments — how to get those. I recently made a BlogSpot interface in PHP/JavaScript and needed to know these things. There are already APIs out there for interfacing with BlogSpot, but I like to reinvent the wheel. Keep reading if you do, too.

I have collected quite a few URLs in my experimenting. I won't bother explaining GET parameters (those ?var=value&var2=value2 things in some URLs) or whatever they are called. I'll just spit out the information, so I hope you're a bit tech-savvy!

BlogSpot provides feeds in Atom and RSS. By default, it uses Atom, but this can be changed to RSS by passing the parameter "alt=rss".


Getting a list of blogs by user

  • You can get a list of blogs by the currently signed-in user with the following URL:
    http://www.blogger.com/feeds/default/blogs/

  • You can get a list of blogs by another user with the following URL:
    http://www.blogger.com/feeds/$user_id/blogs/

    $user_id is the user id of the user. This can be found by going to their profile and copying the numbers from that.

    This method, however, seems to be disabled for most blogs. I wouldn't rely upon it.


Getting a blog id (needed for much of the stuff below)
  • If you got the metafeed above to work, it is in the feed->entry->id XML tag (the last number after the dash).
  • It can also be found in the source code of a blog. Just do a quick search for "blogID=".
  • Most easily, your own blog id can be found in the URL when you go to your blog in Blogger's Dashboard.


Getting a list of posts by blog



Getting a post id (needed for much of the stuff below)

  • The post id can be found in the feed given by the post list above.
    • The last number (after the "-") of feed->entry->id
    • The last number in the URL in the href attribute of the feed->entry->link tag that also has the rel attribute set to "self" (also, on the one set to "edit").
  • It can also be found in the source code of a blog post (do a quick search for "PostID=").
  • Most easily, it can be found when editing a post (look in the URL).

  • While we're on this, also note that the friendly URL can be obtained from the feed in the href attribute of the feed->entry->link tag that has the rel attribute set to "alternate".


Getting a list of comments by post

  • To get the comments of a post, the following URL can be used:
    http://${username}.blogspot.com/feeds/$post_id/comments/default

    Sorry, but the username must be known for this one. You can, however, get a list of all of the comments in a blog via the following URL:
    http://www.blogger.com/feeds/$blog_id/comments/default

    The later URL will even return comments of some deleted posts. That makes it ill-suited for some purposes but very useful for others. }:-)

  • Changing default to "summary" or "full" is supported, but it doesn't seem to make much of a difference. (Can comments have summaries?)

    It might be a good idea to nevertheless specify which you want (don't use the default).

  • The following GET parameters are supported:
    • start-index - The page of results to get (starts at 1)
    • max-results - The maximum number of results to get

  • The comment feed does not seem to support sorting or filtering. Also, the maximum number of results that can be returned is a measly 200.

    To get more than 200, you'll have to start with start-index=1&max-results=200, then get the next page with start-index=201&max-results=200. Keep repeating that until the value of the feed->openSearch:totalResults tag in the XML file is not equal to the value of the feed->openSearch:itemsPerPage tag.

  • Comments can be in response to other comments. If this is the case, then a comment entry has an additional link tag with a rel="related" attribute and a href attribute set to the URL specified in the related comment's href attribute of the link tag with a rel="self" attribute.

    In the feed, however, a response to a comment will come before the comment. This makes programming something to group them together rather difficult.

More information and help
http://xmlbeautifier.com/ has proven to anindispensabletool in my working with XML. I plan to one-up it soon (adding some features that would help me), but it's wonderful until then.

https://developers.google.com/blogger/docs/1.0/reference is some reference material on the above.

https://developers.google.com/blogger/docs/1.0/developers_guide_php has a bit of information that can be applied to the above.

If you search for my blog interface source code in the downloads of my website (http://www.nathanbelue.com), it has some useful source code in it, including a PHP file that can get all of the comments of a post and return them in various ways.

No comments:

Post a Comment