Overview

In this lesson, we'll learn how to retrieve the number of pageviews for a particular blog page over a certain period of time. We'll also learn how to retrieve a single blog page, as well as a list of all blog pages.

Pageview properties

The table below shows the list of pageview properties and their descriptions.

Parameter

Type

Description

kind

string

The type of object.

Value: "blogger#page_views"

Note: This value is fixed.

blogId

long

The ID of the blog.

counts[]

list

The list of time range and count pairs for each page.

counts[].timeRange

string

The duration over which the count was estimated.

counts[].count

long

The number of pageviews.

Methods

Get pageviews

We can retrieve the pageview stats for a specific blog by making a GET request to the following endpoint:

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

This endpoint requires the blogId of the blog that we would like to retrieve the pageview stats for.

Request parameters

Parameter

Type

Category

Description

blogId

string

required

The ID of the blog whose pageview stats we want to retrieve.

range

string

optional

The duration from which to retrieve the pageview counts.

Allowable values: "30DAYS", "7DAYS", "all"

Sample code

In the code below, enter the value for the required parameter blogId on line 1. Try adding the optional parameter, range, 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 + '/pageviews'
response = requests.get(url, headers=headers)
printResponse(response)

The above code displays a pageview object that contains the attributes given in the pageview properties table above. An appropriate error message will be displayed if the API call fails.

List pages

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

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

This endpoint requires the blogId of the blog whose pages we’d like to retrieve.

Request parameters

Parameter

Type

Category

Description

blogId

string

required

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

fetchBodies

boolean

optional

"True" to retrieve page bodies, "False" otherwise.

status

string

optional

The type of pages to be retrieved.

Allowable values: "draft" for unpublished pages, "imported" for pages with removed content, "live" for public pages

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 optional parameters, given in the table above, 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://www.googleapis.com/blogger/v3/blogs/' \
+ blogId + '/pages'
response = requests.get(url, headers=headers)
printResponse(response)

The above code displays the complete list of blog pages from the specified blog. The 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#pageList"

Note: This value is fixed.

items[]

list

The list of pages for the specified blog.

Get page information

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

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

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

Request parameters

Parameter

Type

Category

Description

blogId

string

required

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

pageId

string

required

The ID of the page to be retrieved.

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 parameters blogId and pageId on lines 1–2. Try adding the optional parameter, 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 = ''
pageId = ''
url = 'https://www.googleapis.com/blogger/v3/blogs/' \
+ blogId + '/pages/' + pageId
response = requests.get(url, headers=headers)
printResponse(response)

The above code displays the complete page object corresponding to the given pageId and blogId. This page object contains the attributes listed in the page properties table given in the previous lesson. An appropriate error message will be displayed if the API call fails.