Overview

In this lesson, we'll look at various endpoints that'll enable us to retrieve a single blog post and a list of all blog posts. We'll also learn how to search for a post based on some search text.

Methods

List all posts

We can retrieve a list of all blog posts by making a GET request to the following URL:

https://blogger.googleapis.com/v3/blogs/{blogId}/posts

We'll need to specify the blogId of the blog whose posts we want to retrieve.

Request parameters

Parameter

Type

Category

Description

blogId

string

required

The ID of the blog whose posts are to be retrieved.

endDate

datetime

optional

The date till which the posts are to be retrieved.

Format: yyyy-mm-ddThh:mm:ss.ssZ

fetchBodies

boolean

optional

"True" to include posts' body content, "False" otherwise.

Default value: "True"

fetchImages

boolean

optional

"True" to include image URL metadata, "False" otherwise.

labels

string

optional

A comma-delimited list of labels we want to search.

maxResults

integer

optional

The number of posts to retrieve.

orderBy

string

optional

The sort order for the results.

Allowable values: "published" to order by publishing date, "updated" to order by the date of last update

pageToken

string

optional

The next page's pagination token.

Note: This parameter will only be displayed if it exists.

startDate

datetime

optional

The date from when the posts are to be retrieved.

Format: yyyy-mm-ddThh:mm:ss.ssZ

status

string

optional

The status of the posts to retrieve.

Allowable values: "draft," "live," "scheduled"

view

string

optional

The level of details to be retrieved.

Allowable values: "ADMIN," "AUTHOR," "READER"

Sample code

In the code below, enter the value for the required parameter blogId on line 1. Try adding the values for optional parameters to the URL on lines 3–4 to fine-tune your results.

Click the "Run" button to see the output.

Press + to interact
blogId = ''
url = 'https://blogger.googleapis.com/v3/blogs/' \
+ blogId + '/posts'
response = requests.get(url, headers=headers)
printResponse(response)

The above code displays the complete list of blog posts from the specified blog. This output contains the response parameters given in the table below. An appropriate error message will be displayed if the API call fails.

Response parameters

Parameter

Type

Description

kind

string

The type of object.

Value: "blogger#postList"

Note: This value is fixed.

nextPageToken

string

The next page's pagination token.

Note: This parameter will only be displayed if exists.

items[]

list

The list of blog posts.

Get post information

We can retrieve the post information for a single blog post by making a GET request to the following URL:

https://blogger.googleapis.com/v3/blogs/{blogId}/posts/{postId}

This endpoint requires the blogId of the blog that contains the post we would like to retrieve, as well as the postId of the post itself.

Request parameters

Parameter

Type

Category

Description

blogId

string

required

The ID of the blog whose post is to be retrieved.

postId

string

required

The ID of the post to be retrieved.

maxComments

integer

optional

The number of comments to retrieve with the post.

Default value: 0

view

string

optional

The level of details to be retrieved.

Allowable values: "ADMIN," "AUTHOR," "READER"

Sample code

In the code below, enter the values for the required parameters blogId and postId on lines 1–2. Try adding the optional parameters maxComments and view to the URL on lines 4–5 to fine-tune your results.

Click the "Run" button to see the output.

Press + to interact
blogId = ''
postId = ''
url = 'https://blogger.googleapis.com/v3/blogs/' \
+ blogId + '/posts/' + postId
response = requests.get(url, headers=headers)
printResponse(response)

The above code displays the complete post object corresponding to the given postId and belonging to the specified blog. This post object contains the attributes listed in the post properties table given in the first lesson of this chapter. An appropriate error message will be displayed if the API call fails.

Search posts

We can also search for posts by specifying some search text. This endpoint is extremely useful in helping the users search for blog content that matches their interests. In order to do so, we need to make a GET request to the following URL:

https://blogger.googleapis.com/v3/blogs/{blogId}/posts/search?q={q}

This endpoint requires the blogId of the blog in which we want to search for posts. It also requires a search term or text q that will be searched for in the posts.

Request parameters

Parameter

Type

Category

Description

blogId

string

required

The ID of the blog whose posts are to be searched.

q

string

required

The term that is to be searched.

fetchBodies

boolean

optional

"True" to include posts' body content, "False" otherwise.

Default value: "True"

orderBy

string

optional

The sort order for the results.

Allowable values: "published" to order by publishing date, "updated" to order by the date of last update

Sample code

In the code below, enter the values for the required parameters blogId and q on lines 1–2. Try adding the optional parameters, fetchBodies and orderBy, to the URL on lines 4–5 to fine-tune your results.

Click the "Run" button to see the output.

Press + to interact
blogId = ''
q = ''
url = 'https://blogger.googleapis.com/v3/blogs/' \
+ blogId + '/posts/search?q=' + q
response = requests.get(url, headers=headers)
printResponse(response)

The above code displays the list of blog posts from the specified blog containing the given search text. This output contains the response parameters given in the table below. An appropriate error message will be displayed if the API call fails.

Response parameters

Parameter

Type

Description

kind

string

The type of object.

Value: "blogger#postList"

Note: This value is fixed.

nextPageToken

string

The next page's pagination token.

Note: This parameter will only be displayed if it exists.

items[]

list

The list of blog posts.