PowerShell cmdline utility to list Blog Articles in a csv file

As part of the Sitecore MVP application process, last year and the year before, one of the issues I struggled with was listing my blogs in a table format. It took me a few weeks of procrastination and finally I had to sit down one full weekend to pull the list of blog articles manually in date, url and title table format.

Right from then, I was thinking if I could access the google blogger spot api endpoints and then I  could write a PS utility to export the list. So, this weekend I decided to do the same!

Here is a sneak peek of my blog articles from Nov 30 2021 till date:

Here is the Blogger API end point List:

https://developers.google.com/blogger/docs/3.0/getting_started#JSONP

Then, based on this url, I created a GCP account to  register a project and enable the API:

Credit Card Details for trial:


Enable Blogger API:


Enable API page:


Note the try this api button the above page, it gives an explorer to list available api endpoints and test those.

Allow APIs access to your account that is configured to the cc:



API List for reference:


You need api key to access the Blogger api endpoints. So, you need to create credentials here for the same:



Here is how you generate the api key:



My blog articles listed for a date range from Postman:



Note that the api key is used here above.

My project in Google Cloud Platform for reference:


Now, time to write some PowerShell script  code:

So, here is my script that accepts a few params and outputs the blogs in a csv format!

Note that in the below script, blog id is important and I get the same from the following call:



###############################################################


# .\bloglistfordaterange.ps1 -url "https://www.googleapis.com/blogger/v3/blogs/737434465710481871/?key=mysecretapikeyfromgcp&maxPosts=400" -fromDate '2021-11-30T00:00:00-00:00' -toDate '2022-03-31T23:59:59-00:00'

param (

    

    #"https://www.googleapis.com/blogger/v3/blogs/737434465710481871/?key=mysecretapikeyfromgcp&maxPosts=400"

    [Parameter(Mandatory=$true)]

    [string]$url,

    

    #'2021-11-30T00:00:00-00:00'

    [Parameter(Mandatory=$true)]    

    [string]$fromDate,


    #'2022-03-31T23:59:59-00:00'

    [Parameter(Mandatory=$true)]

    [string]$toDate 

    

)


$x=0


$response=Invoke-RestMethod -Uri $url


$filteredresponse=$response.posts.items  | Where-Object {($_.published -gt $fromDate) -and ($_.published -lt $toDate)}


$filteredresponse | Select-Object -Property title,url,published |

  Export-Csv -Path .\bloglist.csv -NoTypeInformation


##############################################################

Blog list stored in csv format stored in file system:


My Published blogs for MVP 2023 nomination ready at any time with just a PS cmdline invocation!


Wanted to take stock of my total blog articles and here is the list of 199 articles in one file!

API Reference: https://developers.google.com/blogger/docs/3.0/reference/posts/list

Comments

Popular Posts