Learn More

Tuesday, January 31, 2012

Basic Blogger Api

blogger logo
The main purpose of the Bloggers Api is to create a client application. With this application you can view and update Blogger content without having to go into your blogger account. Lots of tutorials about bloggers using Blogger Api. Blogger Api works based on the Google Data Api. So we strongly recommend that you first read our topics on Basic Google Data Api.

Users can create a list of blog posts, displaying the contents of those posts, the date of posting, editing, make a post, giving access to comments, and so forth. All of that can be done using Blogger Api.

Before starting, we want you to always remember that, as long as your blog is public then you can display a list of blog posts without having to make authentic. However, if you want to edit, make a post, then you have to do authentic. The scope for authentic blogger is http://www.blogger.com/feeds/. Yes, you're asked for a feed from bloggers. But for now, we are not discuss about how to make authentic for blogger.



Retrieving a list of blog

In practice, blogger is providing a feed for retrieving a list of blog posts. This feed named as metafeed. When you want to retrieve that, you must send a HTTP GET to the following url :

GET  http://www.blogger.com/feeds/profileID/blogs

If you don't know your profileID, you can find it from your view profile inside your blogger dashboard. But, if you have been joining with google+ profile, then you can't find it anymore. You must change your profile from google+ profile into blogger profile. Unfortunately, if you have switched into google+ profile more than 30 days, then you can not switch back again. So save your blogger profile immediately. After you send that url, server will response and give you a xml file like follow:


after that, you can use any programming language for read that feed (xml file). For the next time, we only provide tutorial for javascript. Remember, you don't have to make authentic as long as your blog is public.



Create and Publish a blog post

Before you create and publish a blog post, you must make an authentic first. Then create a xml file with contain <entry> tag. See the example below



you don't have to create <author> tag, because this tag will create automatic. To publish your content, google has been giving instruction as follow "To publish this entry, send it to the blog's post URL as follows. First, place your Atom <entry> element in the body of a new POST request, using the application/atom+xml content type. Then find the blog's post URL in the metafeed by locating the <link> element where the rel attribute ends with #post. The blog's post URL is given as the href attribute of this element, which is in this format: http://www.blogger.com/feeds/blogID/posts/default."

Actually, blogger have created this procedure automatic. Please try, view source of your page, you can do this by right click your page on window browser, then choose view source. You will see code as follow



this code is same meaning with google instruction. Meaning, this code has been create automatic by blogger.



Creating a draft of a post

Creating a draft is same procedure with publishing a post, but it must contain <app:control> tag. See the example below



As a practice, please create a post, but don't publish it. Then open the address http://www.blogger.com/feeds/blogID/posts/default, you will see <app:control> tag. Because at that time, you have been making a draft.



Retrieving blog posts

As what explained on the older post. You must using GET method. And followed with the following url

GET http://www.blogger.com/feeds/blogID/posts/default

Based on our post before. As long as your blog is public and just only for retrieving all blog posts, you can use another way as follow

GET http://www.example.com/feeds/posts/default

If your url requst is correct (200 message), then server (google) will send you a xml feed. From this step, you can use your programming language to read that xml feed. There are parameters for retrieving blog posts. Because, sometimes you don't have to retrieve all blog posts. May be posts with specific label or else. See the table parameters below

ParameterMeaningNotes
altAlternative representation type
  • If you don't specify an alt parameter, the service returns an Atom feed. This is equivalent to alt=atom.
  • alt=rss returns an RSS 2.0 result feed (for reads only). When you request data from a service in RSS format, the service supplies a feed (or other representation of the resource) in RSS format. If there's no equivalent RSS property for a given Data API property, the service uses the Atom property, labeling it with an appropriate namespace to indicate that it's an extension to RSS.
  • alt=json returns a JSON representation of the feed. More information
  • alt=json-in-script Requests a response that wraps JSON in a script tag. More information
  • alt=atom-in-script Requests an Atom response that wraps an XML string in a script tag.
  • alt=rss-in-script Requests an RSS response that wraps an XML string in a script tag.
  • alt=atom-service Requests an Atom service document that describes the feed.
authorEntry author
  • The service returns entries where the author name and/or email address match your query string.
categoryCategory query filter
  • An alternative way to perform a category filter. The two methods are equivalent.
  • To do an OR between terms, use a pipe character (|), URL-encoded as %7C. For example:http://www.example.com/feeds?category=Fritz%7CLaurie returns entries that match either category.
  • To do an AND between terms, use a comma character (,). For example: http://www.example.com/feeds?category=Fritz,Laurie returns entries that match both categories.
/-/categoryCategory query filter
  • List each category as if it were part of the resource's URI, in the form /categoryname/—this is an exception to the usual name=value form.
  • List all categories before any other query parameters.
  • Precede the first category with /-/ to make clear that it's a category. For example, if Jo's feed has a category for entries about Fritz, you could request those entries like this: http://www.example.com/feeds/jo/-/Fritz. This allows the implementation to distinguish category-predicated query URIs from resource URIs.
  • You can query on multiple categories by listing multiple category parameters, separated by slashes. The service returns all entries that match all of the categories (like using AND between terms). For example:http://www.example.com/feeds/jo/-/Fritz/Laurie returns entries that match both categories.
  • To do an OR between terms, use a pipe character (|), URL-encoded as %7C. For example:http://www.example.com/feeds/jo/-/Fritz%7CLaurie returns entries that match either category.
  • An entry matches a specified category if the entry is in a category that has a matching term or label, as defined in the Atom specification. (Roughly, the "term" is the internal string used by the software to identify the category, while the "label" is the human-readable string presented to a user in a user interface.)
  • To exclude entries that match a given category, use the form /-categoryname/.
  • To query for a category that has a scheme—such as &lt;category scheme="urn:google.com" term="public"/&gt;—you must place the scheme in curly braces before the category name. For example:/{urn:google.com}public. If the scheme contains a slash character (/) it should be URL-encoded as %2F. To match a category that has no scheme, use an empty pair of curly braces. If you don't specify curly braces, then categories in any scheme will match.
  • The above features can be combined. For example: /A%7C-{urn:google.com}B/-C means (A OR (NOT B)) AND (NOT C).
entryIDID of a specific entry to be retrieved
  • If you specify an entry ID, you can't specify any other parameters.
  • The form of the entry ID is determined by the service.
  • Unlike most of the other query parameters, entry ID is specified as part of the URI, not as a name=value pair.
  • Example: http://www.example.com/feeds/jo/entry1.
fieldsResponse filter
  • Returns only the requested fields, rather than the full resource representation. For example:
    http://www.example.com/feeds?fields=link,entry(@gd:etag,id,updated,link[@rel='edit']))
    When it receives this request, the server returns a response that contains only only link and entry elements for the feed. In addition, the entry elements returned are partial entries that contain only ETag, ID, updated, and edit link relations.
  • The fields value must be URL encoded, as with all query parameter values.
  • For more information, see the Partial response section.
  • This parameter is currently an experimental feature.
max-resultsMaximum number of results to be retrievedFor any service that has a default max-results value (to limit default feed size), you can specify a very large number if you want to receive the entire feed.
prettyprintReturns an XML response with identations and line breaks
  • If prettyprint=true, the XML returned by the server will be human readable (pretty printed).
  • Default: prettyprint=false
published-min,published-maxBounds on the entry publication date
  • Use the RFC 3339 timestamp format. For example: 2005-08-09T10:57:00-08:00.
  • The lower bound is inclusive, whereas the upper bound is exclusive.
qFull-text query string
  • When creating a query, list search terms separated by spaces, in the form q=term1 term2 term3. (As with all of the query parameter values, the spaces must be URL encoded.) The service returns all entries that match all of the search terms (like using AND between terms). Like Google's web search, a service searches on complete words (and related words with the same stem), not substrings.
  • To search for an exact phrase, enclose the phrase in quotation marks: q="exact phrase".
  • To exclude entries that match a given term, use the form q=-term.
  • The search is case-insensitive.
  • Example: to search for all entries that contain the exact phrase "Elizabeth Bennet" and the word "Darcy" but don't contain the word "Austen", use the following query: ?q="Elizabeth Bennet" Darcy -Austen
start-index1-based index of the first result to be retrieved
  • Note that this isn't a general cursoring mechanism. If you first send a query with ?start-index=1&amp;max-results=10 and then send another query with ?start-index=11&amp;max-results=10, the service cannot guarantee that the results are equivalent to ?start-index=1&amp;max-results=20, because insertions and deletions could have taken place in between the two queries.
strictStrict query parameter checking
  • Set strict=true to verify that each of your query parameters are recognized by the service. An error will be returned if a parameter is not recognized.
  • Default: strict=false
updated-min,updated-maxBounds on the entry update date
  • Use the RFC 3339 timestamp format. For example: 2005-08-09T10:57:00-08:00.
  • The lower bound is inclusive, whereas the upper bound is exclusive.
  • In some cases (such as when using v2.1 or newer of the Calendar Data API), specifying an updated-min that is too far in the past will cause an HTTP 410 (Gone) status to be returned.
Source: google data api

as example, if you want to retrieve a list of blog posts with rss format, then the url is as follow

http://www.blogger.com/feeds/blogID/posts/default?alt=rss       
or 
http://www.example.com/feeds/posts/default?alt=rss



Update a post

For update a post, google has given instruction as follow "To update an existing blog post, first you retrieve the entry you want to update, then you modify it, and then you send a PUT request, with the updated entry in the message body, to the post's edit URL. Be sure that the <id> value in the entry you PUT exactly matches the <id> of the existing entry." If you are doing update, then your feed will contain <updated> tag.



Create a comment

If we want to create a comment, create an atom with <entry> tag as follow:



and to publish it, you can use POST method to the following url

POST http://www.blogger.com/feeds/blogID/postID/comments/default



Retrieving comments

For retrieving all comments, you can use the following method

GET http://www.blogger.com/feeds/blogID/comments/default

But if you only need comments on specific post, then use the following method

GET http://www.blogger.com/feeds/blogID/postID/comments/default


Delete comments

What you must to do for deleting specific comment is using DELETE method on the specific post.



Import and export

Sometimes you need export to other blog or import from other blog. If you want to export then follow the method below

GET http://www.blogger.com/feeds/blogID/archive

and if you want to import then follow the method below

POST http://www.blogger.com/feeds/blogID/archive/full



  1. Yang saya tidak mengerti, cara memperoleh 'profileId'. Setelah kita berhasil login dan memperoleh 3 id (salah satunya auth=XXX). Nah, bagaimana kita bisa mempopulate seluruh blog yang berada di akun tersebut, padahal kita harus memperoleh terlebih dahulu profileid. Terima kasih.

    ReplyDelete
  2. If you are using blogger profile (not using google+ profile), click that. Then you will get your blogger profile ID.

    ReplyDelete
  3. makin bingin saja saya baca2 baca disini.. yang pertama karena pake bahasa inggris, so pasti bahasa inggris saya gk bisa... yang kedua masih lum tahu tentang implementasi json api blogger, tapi saya sangat suka sekali,.. masih tak coba2 semoga berhasil mencobanya...

    ReplyDelete
  4. This was a great guide, I appreciate the fact that you took out all the important stuff out of blogger, my biggest thanks.

    ReplyDelete