One of the most requested features that developers have for the Blogger JSON API is the ability to create posts. So have a quick guess what the following HTTP request does?
POST https://www.googleapis.com/blogger/v3/blogs/8070105920543249955/posts/ HTTP/1.0 Host: www.googleapis.com Authorization: Bearer <OAuth2 key> Content-Type: application/json { "kind": "blogger#post", "blog": { "id": "8070105920543249955" }, "title": "A new post", "content": "With <b>exciting</b> content..." }
That’s right, Blogger API v3 gives you the ability to create posts! Oh, and edit, delete and search them as well!
There is documentation that covers all this new functionality. Firstly we have a Getting Started document that gives you an overview of using the API. Then there is a more detailed Using Blogger API guide that shows how you would use the API. Finally the API Reference that covers the fine details, like argument and result specifications for all the calls.
If you have any questions about how to use this new API, please join in the discussion on the Blogger Developer group.
Recently we released an update to Blogger’s commenting system that enables people to directly respond to comments. This capability is known as Threaded Comments. We are pleased to see quite a few people diving in and writing tutorials, including a screencast. It’s wonderful to see the enthusiasm of our developers!
In this post we will look at what are the changes required to modify a custom template to enable Threaded Comments, once you have fulfilled the requirements outlined in the Threaded Comments announcement post on Buzz.blogger.com. We will then look at how to customise the look and feel of the Threaded Comments using just CSS, and also have a quick peek at alternatives.
Please note, these instructions may not work if your blog’s template is heavily customised. Your template may possibly missing some of the b:includables that the instructions below depend on. Please try the following instructions on your template, but if they don’t work come to our Blogger Developer forum and get some help with patching your template.
b:includable
The first step is to Edit the HTML for your Template, which can be found inside Settings under the Template tab. You must make sure to expand the Widget Templates, as we need to modify the main Blog Widget Template. To find the main Blog Widget code, search for the following Blogger Layouts Template code:
<b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog'>
Inside the b:widget are a series of b:includable blocks. These act a lot like functions in programming languages, in that they can be called from other b:includable blocks to insert chunks of HTML. The only special block is the includable called main, which is where the Layout Template engine starts when rendering the Widget’s content. If you don’t see content inside the b:widget, you need to click the Expand Widget Templates radio button above the edit area.
b:widget
main
The Layout Template should include the following code:
<b:if cond='data:post.showThreadedComments'> <b:include data='post' name='threaded_comments'/> <b:else/> <b:include data='post' name='comments'/> </b:if>
The interesting part is that we have a fork here, implemented as a b:if conditional block, that decides whether to render the comments as threaded or not. The need for this split can be seen on the Threaded Comments announcement on Buzz.blogger.com.
b:if
As a quick aside, if you don’t have this code, but instead just have something like the following:
<b:include data='post' name='comments'/>
Then you can get threaded comments by replacing this b:include with the above logic block, assuming you fulfill the requirements laid out in the Threaded Comments announcement post on Buzz.blogger.com.
Now you can look at the implementation of the threaded_comments includable by searching for the following line of code:
<b:includable id='threaded_comments' var='post'>
This code is responsible for rendering the actual threaded comments to screen. You can choose to override this code block to customise the look of your comments, but it is worth noting that if you do, you won’t get updates to this functionality as we change the implementation in the future.
There are two new data members we have introduced with this feature release that you can use to render comment threads:
data:post.commentSrc
data:post.commentHtml
If you want to change the look and feel of your comments, we strongly recommend you use the Template Designer to set custom CSS to style the Threaded Comments. We suggest you customise the comments by modifying the property "Advanced > Add CSS". For example, you can add the following CSS code to change the look:
.comments blockquote { border: 1px solid black; color: white; font: Helvetica; } // draws a border around comment bodies, sets the text font and colour .comments .inline-thread li { list-style-type: decimal; } // numbers replies
Finally, you can implement your own version of Threaded Comments by walking the data:post.comments directly. This will contain all the comments, ordered by time of comment, now with an optional extra field data:comment.inReplyTo which will contain the id of the parent comment, if there is one.
data:post.comments
data:comment.inReplyTo
id
If you have any questions about how to customise your Blogger Comments, please feel free to drop by the Blogger Developer Forum. We’re glad to help!
posts.list
blogId
fields
items(content,title)
<script src="https://apis.google.com/js/client.js?onload=init"></script>
onload=init
init
function init() { gapi.client.setApiKey('YOUR_API_KEY'); gapi.client.load('blogger', 'v2', function() { // ... }); }
gapi.client.load
var request = gapi.client.blogger.posts.list({ 'blogId': 3213900, 'fields': 'items(content,title)' });
request.execute(function(response) { // ... });
response
for (var i = 0; i < response.items.length; i++) { $("#target").append("<h2>" + response.items[i].title + "</h2>"); $("#target").append(response.items[i].content); if (i+1<response.items.length) { $("#target").append("<hr/>"); } }