Learn More

Sunday, December 23, 2012

Basic Blog Resources of Blogger API v3

blogger gear
Blog Resource is one of resources that operating on Blogger API v3. This resource contain three types in access a blog of a user of Blogger. Each type has different result in JSON script, you can use it depend on your condition. Before you learn this, at least you have API Console of Blogger. On this article, I also give you the JSON property output of each type. So that you can access and take decision, where type you want to use for your application.

Like what we talked above, the three types of Blog Resources is:

  1. listByUser: this type will retrieve blogs of a user. No matter how many blogs you was mad.
  2. get: this type will retrieve info of your specific blog based on blog ID. This type can also retrieve your latest posts. 
  3. getByUrl: this type is almost same with get type. The different is this type retrieve your specific blog using URL of your blog that you want to check. And this type can't retrieve your latest posts.
Ok, we will discuss it one by one

JOIN WITH OUR THREELAS APP. YOU CAN JOIN WITH YOUR FRIENDS TO DISCUSS ALL THREELAS ARTICLES, SHARE, AND SEE WHAT YOUR FRIENDS ACTIVITIES. Lear more.

A. listByUser

If you want to use this type, you should know the ID of your blogger account. But if you join your blogger profile with your G+ (googleplus) profile, then your truly ID will hard to know again. Then you can solve this will give self property on HTTP request. Below is two ways of HTTP request how to use listByUser

GET https://www.googleapis.com/blogger/v3/users/userId/blogs
or by using
GET https://www.googleapis.com/blogger/v3/users/self/blogs
Output of this HTTP request is an array of items. The number of array very depend on how many blogs you have. Below is the result of JSON ouput

{
"kind": "blogger#blogList",
"items": [
{
"kind": "blogger#blog",
"id": "FISTBLOGID",
"name": "TITLEOFFIRSTBLOG",
"description": "DESCRIPTIONOFFIRSTBLOG",
"published": "FIRSTTIMETHISBLOGISCREATED",
"updated": "LATESTUPDATEOFTHISBLOG",
"url": "URLOFFISTBLOG",
"selfLink": "SELFLINKOFFIRSTBLOG",
"posts": {
"totalItems": 23,
"selfLink": "SELFLINKPOSTSOFFIRSTBLOG"
},
"pages": {
"totalItems": 2,
"selfLink": "SELFLINKPAGESOFFIRSTBLOG"
},
"locale": {
"language": "in",
"country": "",
"variant": ""
}
}
]
}

B. get

Different with listByUser, you don't need to know ID of blogger user. This type will retrive blog information based on ID of a blog. This type is also able to retrive your latest posts. If you want to get latest post, what you should to do is just add maxPosts on HTTP request method. On our early posts, that is http://www.threelas.com/2012/12/learn-basic-blogger-api-v3.html, we gave a demo about this type. Below is HTTP request method for this type

GET https://www.googleapis.com/blogger/v3/blogs/blogId
And if you are using maxPosts (example is 1 post), then the HTTP request above become
GET https://www.googleapis.com/blogger/v3/blogs/blogId?maxPosts=1
If you are using the first HTTP request method, then the JSON output become
{
"kind": "blogger#blog",
"id": "BLOGID",
"name": "BLOGNAME",
"description": "BLOGDESCRIPTION",
"published": "TIMEOFBLOGWASCREATED",
"updated": "LATESTUPDATED",
"url": "URLOFBLOG",
"selfLink": "SELFLINKURLOFBLOG",
"posts": {
"totalItems": TOTALPOSTS,
"selfLink": "SELFLINKURLOFPOSTS"
},
"pages": {
"totalItems": TOTALPAGES,
"selfLink": "SELFLINKURLOFPAGES"
},
"locale": {
"language": "en",
"country": "",
"variant": ""
}
}

However, when you use second HTTP request method, the output become
{
"kind": "blogger#blog",
"id": "BLOGID",
"name": "BLOGNAME",
"description": "BLOGDESCRIPTION",
"published": "TIMEOFBLOGWASCREATED",
"updated": "LATESTUPDATE",
"url": "BLOGURL",
"selfLink": "SELFLINKOFBLOG",
"posts": {
"totalItems": TOTALPOSTS,
"selfLink": "SELFLINKOFPOSTS",
"items": [
{
"kind": "blogger#post",
"id": "LATESTPOSTID",
"blog": {
"id": "BLOGID"
},
"published": "TIMEOFPOSTWASCREATED",
"updated": "LATESUPDATEPOST",
"url": "POSTURL",
"selfLink": "SELFLINKLATESTPOST",
"title": "TITLEOFLATESTPOST",
"content": "CONTENTOFLATESTPOST",
"author": {
"id": "IDOFPOSTAUTHOR",
"displayName": "NAMEOFPOSTAUTHOR",
"url": "GOOGLEPLUSAUTHORURL",
"image": {
"url": "IMAGEOFAUTHOR"
}
},
"replies": {
"totalItems": "TOTALCOMMENTS",
"selfLink": "SELFLINKCOMMENTS"
},
"labels": [
"FIRSTLABEL",
"SECONDLABEL"
]
}
]
},
"pages": {
"totalItems": TOTALPAGES,
"selfLink": "SELFLINKPAGES"
},
"locale": {
"language": "en",
"country": "",
"variant": ""
}
}

C. getByUrl

Like what we had explained above, that this type only need URL of a blog. Then this type will retrive blog information. Result of this JSON output is almost same with listByUser. The most different between both are getByUrl only retrive one blog, but listByUser will retrieve all blog of a user. Below is the result of getByUrl JSON


{
"kind": "blogger#blog",
"id": "BLOGID",
"name": "BLOGNAME",
"description": "BLOGDESCRIPTION",
"published": "THEFIRSTTIMEBLOGWASPUBLISHED",
"updated": "LATESTUPDATE",
"url": "BLOGURL",
"selfLink": "SELFLINKBLOG",
"posts": {
"totalItems": TOTALPOSTS,
"selfLink": "SELFLINKPOST"
},
"pages": {
"totalItems": TOTALPAGES,
"selfLink": "SELFLINKPAGES"
},
"locale": {
"language": "en",
"country": "",
"variant": ""
}
} After you read our explanation about Blog Resources of Blogger API v3. Now, time to learn trick of these types and example code. But, don't to fast. Learn it again, then we will give to you on the next posts.

  1. Fantastic website!

    Is there a way with Javascript to retrieve post information like header and posting snippet by passing the link (href)?

    I found no way so far.

    Background is that I want to show the user as in a mouse effect the complete headline of historical and often shortended links of the blog archive and an additional posting snippet.



    Somehow like the feed but in this case when mouse over show complete headline and some lines of posting text.


    Do you have an idea?


    Best regards

    ReplyDelete
  2. Sorry late to response @Akzent:disqus , yes you can retrieve that you want, posting snippet complete with href. Tell us your complete idea...

    ReplyDelete
  3. The idea ist rather simple:

    a function to deliver the complete the header text and a snippet of the posting text.

    In a way like this:

    getPostSnippet (href) { // e. g. http://www.threelas.com/2012/12/basic-blog-resources-of-blogger-api-v3.html
    // get header text and snippet via feed api or post api or ....???
    return
    }


    Important: Javascript and no OAuth.

    Thx!

    ReplyDelete
  4. Like this https://productforums.google.com/forum/#!msg/blogger/kHS5D_H6Z_c/FjQs5JRS3hIJ
    No KEY, no OAuth

    ReplyDelete
  5. There are a easy way to get all you need without Oauth. You can use JSON Feed API. You can read basic json feed on http://www.threelas.com/2012/02/basic-blogger-json-feed-api.html and you can see the demo with jquery ajax on http://www.threelas.com/2012/09/blogger-json-feed-with-jquery-ajax.html. We explain it complete and easy to read. Many people like these articles.

    Or, if you any suggestion a tutorial, you can request to us.

    Thank you,

    Putri

    ReplyDelete
  6. Your question was answerred, please see your retread above. You can also use javascript code to retrieve what you want without Oauth, please read the tutorial on http://www.threelas.com/2012/05/how-to-retrieve-posts-using-blogger.html


    All tutorials in here is related one by one. so please also the another topic with same categories.

    ReplyDelete
  7. Hi Petri,

    thanks a lot for you kind engagement.

    I'm sorry, but I cannot see a way to get a post if only have a url as input parameter

    Or, please, how can I can get the post or parts of it if only have this as input parameter:



    "http://www.threelas.com/2011/12/how-to-making-blogger-template.html"


    When I see it correctly one always has to load down all posts and then loop through it until the right comes...



    Best regards
    Peter

    ReplyDelete
  8. Hi Peter,

    First, please correct if wrong... You want to get all information on a specific url of a blog? You can't do that if using javascript or conventional json feed api. You can solve your problem with blogger json feed api v3. Below this is the example

    https://www.googleapis.com/blogger/v2/blogs/8508954923570954753/posts/6627038485254057059

    where 8508954923570954753 is blog ID and 6627038485254057059 is post ID. From here, you can get information on specific url of a blog. You don't have to use oauth as long as the current blog is public.

    ReplyDelete
  9. Hi Petri,
    "You want to get all information on a specific url of a blog?"
    Yes, that's correct and I wonder why this isn't possible yet i an easy manner.

    Thx a lot for your engagement.
    Best regards
    Peter

    ReplyDelete
  10. Hi Peter, I am so sorry for uncomfortable for this question. For now, only blogger json feed api v3 or v2 (require oauth) can solve your question.


    But actually, you can also use another way. You can retrieve information on a specific url of a blog without oauth, you can use blogger gadget.


    But for now (until January 9, 2013), we are not provide this tutorial. Soon we will create it.

    ReplyDelete
  11. Hi Putri,
    there is no Blogger gadget that supports the desired functon "take URL give blog post".

    regards

    ReplyDelete
  12. yes... blogger gadget can't retrieve of specific url of a blog but specific of current url of a blog. I just to give u some advice if u like.

    ReplyDelete
  13. "...blogger gadget can't retrieve of specific url of a blog but specific of current url of a blog"

    I think that's exactly what I want: Post information based on specific psot URL
    Advice is strongly welcome.
    Thx!!.

    ReplyDelete
  14. I am so sorry can't help you more, coz blogger is not my mine.

    ReplyDelete