I know less about all these blogging APIs than I thought I did, and than I should: today I just set out to begin work on an import function for semiBlog, allowing it to import a complete blog from e.g. WordPress. The idea is that you could say "Here is the URL of my blog, now go and get all the posts, so that I can work on them in semiBlog." Without thinking, I assumed that any self-respecting blogging API would allow one to say something like "Give me all posts" or at least "Give me the postIDs of all posts". However, after looking around for a while, it seems that this functionality does not exist. So maybe I should take a step back and have a closer look at all the various APIs. I'll collect all the relevant information here in this post.
Blogger API
I started my quest for knowledge with the Blogger API (which is actually deprecated by Blogger itself, in favour of the Atom API). The spec lists the following API calls:
- blogger.newPost
Makes a new post to a designated blog. Optionally, will publish the blog after making the post.
- blogger.editPost
Edits a given post. Optionally, will publish the blog after making the edit.
- blogger.getUsersBlogs
Returns information on all the blogs a given user is a member of.
- blogger.getUserInfo
Authenticates a user and returns basic user info (name, email, userid, etc).
- blogger.getTemplate
Returns the main or archive index template of a given blog.
- blogger.setTemplate
Edits the main or archive index template of a given blog.
None of these strike me as particularly helpful in my task of getting all posts for a given blog.
MetaWeblogAPI
The MetaWeblogAPI is "designed to enhance the Blogger API", as its specification states. That document lists the following API calls:
- metaWeblog.newPost (blogid, username, password, struct, publish)
returns string
- metaWeblog.editPost (postid, username, password, struct, publish)
returns true
- metaWeblog.getPost (postid, username, password)
returns struct
- metaWeblog.newMediaObject (blogid, username, password, struct)
returns struct
- metaWeblog.getCategories (blogid, username, password)
returns struct
- metaWeblog.getRecentPosts (blogid, username, password, numberOfPosts)
returns array of structs
Ah, I seem to be getting closer: getPost and getRecentPosts seem to help somewhat. getPost will of course only give me one post, specified by its postID. The documentation for getRecentPost says: If numberOfPosts is 1, you get the most recent post. If it's 2 you also get the second most recent post, as the second array element. If numberOfPosts is greater than the number of posts in the weblog you get all the posts in the weblog. That last bit is interesting - however, I still have to know how many post there are. Alternatively, I could just pass a ridiculously high number, and hope that it will be higher than the total number of posts. Hm...
Out of curiosity I tried passing 0 as the numberOfPosts parameter. This is not documented in the spec, but with my WordPress 2.0.2 test blog it consistently gives me all posts back - just what I wanted! :-) After stumbling upon this, I tried to figure out if this was documented anywhere. All I found was the statement "using blogger.getRecentPosts with the number 'zero' returns all posts in the blog". Apart from the fact that it seems slightly wrong (it should read metaWeblog.getRecentPosts), I couldn't find its original source. The statement appears in various places on the web, which all apparently copy from each other (and now it also appears here). Also, I'm afraid I can't expect this to work with all systems supporting MetaWeblog API - or can I?