Dec 16, 2011

f Comment

How to Get HTML Body of a Post via Google Blogger's Java API?

Amazon For bloggers out there who use Java API to retrieve and update your blog's posts do you not find it annoying that getting the HTML content of a post is not as straightforward as it should be?

The Problem
Here's the issue. Suppose you create a new post in your Blogger account (by going to Posting => New Post) and the post body looks like this:

<span class="highlight">Q: How do I get the HTML body of a post via Google's Blogger Java API?</span>
For bloggers out there who use Java API to retrieve and update your blog's posts do you not find it annoying that getting the HTML content of a post is not as straightforward as it should be?
<span class="highlight">The Problem</span>
Here's the issue. Suppose you create a new post in your Blogger account (by going to Posting => New Post) and the post body looks like this:

Save the post. Now you'd like to retrieve the HTML code of this post via Blogger's Java API. How do you do that? What method do you use? Unfortunately the Java API is totally vague about it. Read on to see the solution

To see how to get every post of a blog please read Getting Every Post of a Blog via Blogger API!
SOLUTION
It turns out the solution is simple. Suppose 'entry' refers to the post's com.google.gdata.data.Entry variable. You simply call the getContent() method and the getHtml() method as follows:
String htmlContent=((HtmlTextConstruct)((TextContent) entry.getContent()).getContent()).getHtml();
The String variable 'htmlContent' should contain the entire HTML code of this post.

If you have any questions let me know and I will do my best to help you!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael