How to get postid

16 views
Skip to first unread message

Raj

unread,
Oct 31, 2007, 5:35:29 AM10/31/07
to Google Data API
I am using Google data API to download post and comments to load into
my local database. I am able to fetch the post. To fetch the comments,
I need blog id and post id. Does anyone know how and from where to
reterive this programatically? I believe you can user
AtomEntry.id.AbsoluteURI and then do a substring to get the blog id
and post id. I was wondering if anyone know a simpler way of doing
this? Or a simpler way of downloading the comments for a post?

Any help would be much appreciated.

Thanks

Raj

Jeff S

unread,
Nov 1, 2007, 8:11:23 PM11/1/07
to Google Data API
Hi Raj,

I think I saw two questions in your post, the first was how to find
the comments and the second was a way to get the blogID and postID. I
think I know an answer to the first question which doesn't require you
to find the blogID and postID, but I'll answer that too because there
are cases where having those IDs comes in handy.

I assume that you're getting the list of posts with a URL like this:
http://[blogName].blogspot.com/feeds/posts/default

You asked specifically about finding the comments feed URL, and it
turns out that a link to the comments feed is included in the post
entries that you find from your initial query for a list of the posts
in the blog. Each post entry has a couple of link's which point to
"replies". The link that you are interested in has a rel of 'replies'
and a type of 'application/atom+xml' (instead of html/text). The
comment link element looks like this:

<link rel='replies' type='application/atom+xml' href='http://
[blogName].blogspot.com/feeds/[postID]/comments/default' title='Post
Comments'/>

I guess the simplest way to get the comments and post contents would
be to get a feed containing all of the posts then perform a GET on the
Atom replies link in each of the entries. How does this look to you?

Now about the blogID and postID. There are a few places you can look
to see the blogID and the postID for a blog post and I think most of
the following information is in the protocol developers guide (thought
it may be scattered around):

http://code.google.com/apis/blogger/developers_guide_protocol.html

Once you get the feed of your blog posts, you can look at each entry
to see the blogID and postID. A good place to find this is in the edit
link of a post's entry. The edit link looks something like this:

<link rel='edit' type='application/atom+xml'
href='http://www.blogger.com/feeds/[blogID]/posts/default/[postID]'>
</link>

You could also look at the contents of the id within the post's entry.
The id is in the following form:

<id>tag:blogger.com,1999:blog-[blogID].post-[postID]</id>

Parsing the above id sounds like it was your original idea, so I'm not
sure if parsing the URL in the edit link would be any easier.

Happy coding,

Jeff

Reply all
Reply to author
Forward
0 new messages