Pyhton auto post to blogger using Google blogger API

    Here we are going to see the end to end flow of auto post into blogger using python and google blogger API.
    For example, if you want to show the currency value against the $ in your blog, It is hard to update an hour/day wise by manual. To solve this we can generate the python script to update the blog information through the google blogger API. We have the many use case using python automation concept. In fact, We can automate the blog writing through the below script combined with the content/webs-crawler . The web crawler link is attached here.

It will useful for us to reduce the time consumption and work load. 

Over view:

Python code automatically post to blogger and publish the post with out human intervention.

Approaches:

  • Google oauth2 authentication
  • Google blogger V3 API  (python client library)
  • Python program to automate

Prerequisite:

  1. Python 2.7, or 3.4 or higher
  2. Blogger account - Create the blogger account if not through this link
Need to install the python google client library to use in future.

Managed installation

Use pip or setup-tools to manage your installation (you might need to run sudo first).
For pip use this blow command to install the library.

$ pip install --upgrade google-api-python-client

Google Authentication setup

      Requests to the Blogger JSON API for public data must be accompanied by an identifier, which can be an API key or an auth token.To acquire an API key, visit the APIs Console and follow the below instructions.

Step 1: Here you need to create the project from the top menu. After click the menu it will land the below screen.

Step 2: Click the left side menu and then click APIs & Services menu . In that click the credential option.  look at the below image


Step 3: Click Create Credential button and choose the Oauth client ID.


Step 4: Choose the necessary options from the list. In our example I am going to choose Other. Enter the credential title for future reference.


Step 5: Finally we generated the oauth file. We must download the auth detail to give reference in python programming.


Upto now we finished the authentication setup and install necessary library.

Auto post python script

        In below, you may find the python code to create the simple post and publish it into the blogger . The code snippet give below,



  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
# coding: utf-8

# ### Python code to auto post to blogger
# @author Ramachandran K <ramakavanan@gmail.com>
# 

# In[1]:


import sys
import os
import pickle
from oauth2client import client
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request


# ##### Adding the blog id and scope of the blogger. 
# The scope will play the major rolw. It will generate the feasibility to work through the API.

# In[3]:


BLOG_ID = "xxxxxxxxxxxxxxxxxxxxxxxx"
SCOPES = ['https://www.googleapis.com/auth/blogger', 'https://www.googleapis.com/auth/drive.file']


# #### Function to generatet the blogger and drive service
# Here we are using the pickle to store and retrive the credential file. The pickle will store the data in bytes. 
# The normal human cant read that pickle file.

# In[4]:


def get_blogger_service_obj():

    creds = None
    if os.path.exists('auth_token.pickle'):
        with open('auth_token.pickle', 'rb') as token:
            creds = pickle.load(token)
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('auth_token.pickle', 'wb') as token:
            pickle.dump(creds, token)
    blog_service = build('blogger', 'v3', credentials=creds)
    drive_service = build('drive', 'v3', credentials=creds)

    return drive_service,blog_service


# In[6]:


drive_handler, blog_handler = get_blogger_service_obj()


# ### Function to get the blog information 

# In[7]:


def get_blog_information(api_handler=None, blog_max_posts=3):
    try:
        if not api_handler:
            return None
        blogs = api_handler.blogs()
        resp = blogs.get(blogId=BLOG_ID, maxPosts=blog_max_posts, view='ADMIN').execute()
        for blog in resp['posts']['items']:
            print('The blog title : \'%s\'  and url : %s' % (blog['title'], blog['url']))
    except Exception as ex:
        print(str(ex))


# In[8]:


get_blog_information(blog_handler)


# In[6]:


import json


# In[9]:


data = {
    'content': '<b> Welcome ! </b> <br/> This is my first automated post through API.',
    'title':'Python post sample',
    'labels' : ['First Post'],
    'blog': {
        'id': BLOG_ID, # The identifier of the Blog that contains this Post.
      },
}


# ### Getting post objects and creating post 

# In[11]:


posts = blog_handler.posts()
res = posts.insert(blogId=BLOG_ID, body=data, isDraft=True, fetchImages=True).execute()


# #### Printing response from the server 

# In[13]:


res


# In[ ]:

    Here we are using the pickle to store and retrieve the confidential information. we have the functions to create the blogger, drive service. I used the blogger to save the image as of now it doesn't need . The post is saved in draft for the above example. Make changes in isDraft as False to publish with in a minute.

   Here we are used only blog information and post creation API.  To know more API details please visit this link,

   For API request and response detail documentation find here.

The above examples are covered only minimal  things. To explore more please visit the google official site.

https://developers.google.com/blogger

Thanks for spending your valuable time to read this blog. Please post your feedback, which help me to improve further more. 

Comments

  1. Cool stuff . It helped me to setup auto post in my blogger :)

    ReplyDelete
    Replies
    1. good article visit https://emeaexpress.com for more such articles

      Delete
  2. It is really helpful.This is the reason why learning Python is very important.

    ReplyDelete
    Replies
    1. its not working can you hep me

      its show credentials.json file not founded

      Delete
  3. what exactly the changes we need to make in the code

    ReplyDelete
  4. Machine Learning Online Training Get the knowledge of an in-depth overview of machine learning online training topics with real-time data from the best machine learning course provided by Evantatech.

    ReplyDelete
  5. https://www.cuahangtemplate.com/

    ReplyDelete
  6. I had to activate Blogger API v3 from dashboard to make it work.
    Thanks, now I can automate my blog :)

    ReplyDelete
  7. Thanks for sharing and it was useful and knowlegable blog.Keep posting. otherwise anyone wants to learn Advanced Java Course so contact here- +91-9311002620 or visit website- https://www.htsindia.com/Courses/java/advanced-java-training-institute-in-delhi

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Its really awesome post for interesting candidates who are going to join you and it is a best reputed center otherwise if any one want to increase his\her skill in python or start up in a python contact us on 9311002620 and visit our further websites https://www.htsindia.com/Courses/python/python-training-institute-in-south-delhi

    ReplyDelete
  10. Skills Hai to Future Hai. Learn Python Programming Languages & Grow Your Skills and Future.

    python training institute in delhi
    python training course in delhi

    ReplyDelete
  11. This article is a great article that I have seen in my python programming career so far, Its helps a lot in Python auto post to blogger using Google blogger API, and will continue to do so in the future.


    hire python developers in US

    ReplyDelete
  12. Thanks for this great and helpful post. it is really knowledgeable post. keep it up. keep poating. otherwise anyone wants to learn Python course so, contact here- +91-9311002620 or visit website- https://www.htsindia.com/Courses/PYTHON/python-training-institute-in-delhi

    ReplyDelete
  13. Thank you for your post
    Kapitaz.com

    ReplyDelete
  14. Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective.

    Python Training Institute in South Delhi

    ReplyDelete
  15. Nice post! You should check out this website for a functional, secure, 100% easy to use WORDPRESS PLUGIN which protect your content. Free or paid content! You decide whether you want to offer your memberships completely for free or paid.

    ReplyDelete
  16. Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective.

    Python Training Institute in Delhi

    ReplyDelete
  17. I really appreciate your hard work you put into your blog and detailed information you provide. Further More Information About Python training institute in Delhi Contact Here-+91-9311002620 Or Visit Website- https://www.htsindia.com/Courses/python/python-training-institute-in-south-delhi

    ReplyDelete
  18. Thanks for sharing this Information.
    Learn Free Python Programming

    ReplyDelete
  19. Thanks for sharing this post if anyone looking for Core and Advanced Java training institute in delhi so contact here +91-9311002620 visit https://www.htsindia.com/java-training-courses

    ReplyDelete
  20. Your content is really good thanks for sharing this post thank you if anyone looking for Core and Advanced Java training institute in delhi so contact here +91-9311002620 visit https://www.htsindia.com/java-training-courses

    ReplyDelete

  21. Outstanding blog with lots of information. Useful one and I have bookmarked this page for my future reference.
    Python course in Velachery
    Python Training in T.Nagar
    Python Training in Porur

    ReplyDelete
  22. Big thank you for sharing this post its very knowledgeable and very helpful i hope that you will continue to post these kinds of contents in future apart from that if anyone looking for e accounting institute in delhi so Contact Here-+91-9311002620 Or Visit Website- https://www.htsindia.com/Courses/Tally/e-accounting-training-course

    ReplyDelete
  23. This comment has been removed by the author.

    ReplyDelete
  24. thank you for sharing this post its really awesome apart from that if anyone looking for e accounting institute in delhi so Contact Here-+91-9311002620 Or Visit Website- https://www.htsindia.com/Courses/Tally/e-accounting-training-course

    ReplyDelete
  25. Excellent Blog, I like your blog and It is very informative. Thank you
    Python online training
    best online python course

    ReplyDelete
  26. Very informative article, which you have shared here about the python language. After reading your article I got very much information and it is very useful for us. I am thankful to you for sharing this article here.
    python language learning portal

    technical language learning portal

    ReplyDelete
  27. This blog has the relevant data according to the topic and precise to the topic.
    Hadoop Training in T Nagar
    Hadoop Training Institute
    Java course

    ReplyDelete
  28. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.

    No-1 Python Training Institute in Delhi with Placement Assistance

    ReplyDelete
  29. thank you, please visit informasi harga to update information about good prices.

    ReplyDelete
  30. I want to leave a little comment to support and wish you the best of luck. We wish you the best of luck in all your blogging endeavors. Otherwise if any One Want to Learn Complete Python Training Course - No Coding Experience Required So Contact Us.

    Complete Python Training Course - No Coding Experience Required

    ReplyDelete
  31. High Technologies Solutions is another great institute located in East Delhi which is worth considering. It was established in 2000.

    Best Institute for Python training institute in Delhi, India

    Top Advanced Excel Training Institute in Delhi with Placement Assistance

    ReplyDelete
  32. I really enjoyed while reading your article, the information you have mentioned in this post is really good. I am waiting for your upcoming post.

    Best Institute for 3D Max Training in Delhi, NCR
    Best Institute for Staad Pro Training In Delhi, NCR

    ReplyDelete
  33. Transfer Game Menggunakan Flashdisk/ Hardisk External ke Hardisk Internal PS3 Melalui File Manager Transfer Game dari PC/ Komputer/ Laptop ke Hardisk Internal PS3

    ReplyDelete
  34. I am sorry but. I use your code above. But I get an error "FileNotFoundError: [Errno 2] No such file or directory: 'credentials.json'".

    I already have downloaded this file. But I don't know which folder in my Google Drive I should upload it.

    I try coding in colab. Should I do that or not?
    Thank you

    ReplyDelete
  35. Well It Was Very Good Information for Learners I Was Really happy See This Article... Thanks for sharing such an amazing post with us and keep blogging.

    Get Learn Complete SAP Training Course by Reputed Institute
    Core to Advanced Level JAVA Training institute in Delhi, NCR

    ReplyDelete
  36. This was a nice article and I was really impressed by reading it. We are also offering training on all software.

    Know about the AutoCAD Training Course & Fee Structure
    web designing course in south Delhi

    ReplyDelete
  37. This post is so insightful and gives me a very nice piece of knowledge about car wash app development company. I visit your blog for the first time, but I was really impressed. Continue posting as I will come every day to read it.

    ReplyDelete
  38. rabie ayad

    rabie ayad is top cricek player in Labanon. In the age of 18 he set recorld of fastest century. rabie ayad is Labanon born cricket player and entrepreneur. rabie ayad hobbie to play cricket from his childhood. He also love to watch cricket and tennis matches.

    ReplyDelete
  39. This post is so helpful. Keep updating us with more information
    Graphic Features
    Graphic Design Elements

    ReplyDelete
  40. Thankyou for sharing this blog this is really helpful and informative. Great Share! Else anyone interested in Python Couse, Contact Us On 9311002620 or You can Visit our Website : https://www.htsindia.com/Courses/python/python-training-institute-in-south-delhi

    ReplyDelete
  41. Thank you so much for sharing this information. Appreciated your blog your Post Else anyone interested in Python Couse, Contact Us On 9311002620 or You can Visit our Website : https://www.htsindia.com/Courses/python/python-training-institute-in-south-delhi

    ReplyDelete
  42. This post is so helpfull and informative.keep updating with more information...
    Selinium Testing
    Selenium Testing Jobs

    ReplyDelete
  43. This blog is very nice , you write the quality content. I read all of your blog. If anyone want to know more about pyhton or want to learn can contact me at 9311002620 or can visit our website https://www.htsindia.com/Courses/python/python-training-institute-in-south-delhi

    ReplyDelete
  44. Your post is really good thanks for sharing these kind of post but if anyone looking for Best Consulting Firm for Fake Experience Certificate Providers in chennai, India with Complete Documents So Dreamsoft Consultancy is the Best Place.Further Details Here- 9599119376 or VisitWebsite- https://experiencecertificates.com/experience-certificate-pr

    ReplyDelete
  45. This post is so helpfull and informative.keep updating with more information...
    Demand For Data Scientists
    Data Science Field

    ReplyDelete
  46. I really like and appreciate your post.Really thank you! Fantastic.
    Visit us: Ui Path Course Online
    Visit us: Ui Path Certification Course

    ReplyDelete
  47. Thank you for sharing this kind of informative post i your content helped me alot apart that if anyone looking for best institute for java training so contact here +91- 9311002620 or visit https://www.htsindia.com/java-training-courses

    ReplyDelete
  48. Nice blog it include the very nice information. It attract me to read this blog. Dreamsoft Consultancy is one of the Leading Company in India who Provide Genuine Experience Certificate in Gurugram. So Contact here and Get all Details. Contact Us with Get all Details- 9599119376 or check Our Website- https://experiencecertificates.com/experience-certificate-provider-in-Gurgaon.html



    ReplyDelete
  49. Thanks for writing blog, your blogs are very nice and knowledgeable. If anyone want to know more about 3D Max Course or want to learn can contact me at 9311002620 or can visit our website

    3DS Max Architecture Modeling - Autodesk 3DS Max Training

    ReplyDelete
  50. nice, https://gooweather.com/

    ReplyDelete
  51. Jubilant to read your blog. One of the best I have gone through. If anyone want to get experience certificate in Chennai. Here the Dreamsoft is providing the genuine experience certificate in Chennai. Dreamsoft is the 20 years old consultancy providing experience certificate. You can contact at the 9599119376 or can go to our website at https://experiencecertificates.com/experience-certificate-provider-in-chennai.html

    ReplyDelete
  52. Thanks for sharing this amazing post this is the content i really looking for, it's very helpful i hope you will continue your blogging anyway if anyone looking for Advance excel training institute in delhi contact us +91-9311002620 visit-https://www.htsindia.com/Courses/business-analytics/adv-excel-training-course

    ReplyDelete
  53. This blog is very useful it includes very knowledgeable information. Thank you for sharing this blog with us. If anyone want to experience certificate in Bangalore can call at 9599119376 or can visit https://experiencecertificates.com/experience-certificate-provider-in-bangalore.html

    ReplyDelete

  54. This blog is very useful it includes very knowledgeable information. Thank you for sharing this blog with us. If anyone want to experience certificate in Bangalore can call at 9599119376 or can visit https://experiencecertificates.com/experience-certificate-provider-in-Hyderabad.html

    ReplyDelete
  55. Your blog is very nice and interesting. Your way of writing this blog forced me to read the full blog. Being a new reader, your blog increased my interest in reading. If anyone is interested for Fake Experience Certificate in Mumbai here we have the chance for you, Dreamsoft is providing is Fake experience certificate in Mumbai. To get you experience certificate in Mumbai you can contact at 9599119376. or can visit our website at https://experiencecertificates.com/experience-certificate-provider-in-mumbai.html

    ReplyDelete
  56. Thank you for sharing this valuable information with us. Keep writing this type of the knowledgeable blogs. If anyone is interested for taking experience certificate in Gurugram.
    Dreamsoft is the 20years old consultancy providing experience certificate in Gurugram for your experience certificate in Gurugram you can contact at – 9599119376 or visit our website athttps://experiencecertificates.com/experience-certificate-provider-in-Gurgaon.html

    ReplyDelete
    Replies
    1. https://appgrouplinks.blogspot.com/2022/04/pune-whatsapp-groups.html

      Delete

  57. Good to hear you views about I totally agree to your views. For filling the gap in the courier Dreamsoft will provide the Genuine experience certificate in Bangalore, so here is your turn to grab the opportunity and to take your experience certificate in Bangalore. The one who is interested for the experience certificate in Bangalore may contact at 9599119376 or can visit our website at https://experiencecertificates.com/experience-certificate-provider-in-bangalore.html

    ReplyDelete
  58. It's very nice of you to share your knowledge through posts. I love to read stories about your experiences. They're very useful and interesting. I am excited to read the next posts. I'm so grateful for all that you've done. Keep plugging. Many viewers like me fancy your writing. Thank you for sharing precious information with us. Best subnetting cheat sheet service provider.

    ReplyDelete
  59. I have read all the comments and suggestions posted by the visitors for this article are very fine, we will wait for your next article so only. Thanks!

    Python Training Institute in Delhi-Grow your Career with US
    Explore to Your Career to Learn Complete Digital Marketing Course in Delhi

    ReplyDelete
  60. Thanks for sharing the best information and suggestions, I love your content, and they are very nice and very useful to us.
    Best PTE institute in Ambala
    Best PTE Coaching in ambala
    IELTS Institute in Ambala

    ReplyDelete
  61. Nice blog ,thanks for the sharing this content keep sharing this type of content

    High Technologies Solutions Provide You the best knowldge of python
    here you can start from zero to advanve level
    for more information please call us on 9311002620
    Visit our website for more details https://www.htsindia.com/Courses/python/python-training-institute-in-south-delhi

    ReplyDelete
  62. https://www.lazada.co.id/bdg39
    https://www.lazada.co.id/bdg102
    https://www.lazada.co.id/cod-fashion-store
    https://www.lazada.co.id/alfazzafashion
    https://blibli.app.link/dWoHugic3mb
    https://www.lazada.co.id/raihan-fashion-store
    https://zilingotrade.id/id/storefront/SEL8151419184
    https://www.youtube.com/watch?v=LFXrb6H7jww

    ReplyDelete
  63. Thanks for this blog, keep sharing your thoughts like this...
    UI UX Course in Chennai
    UI UX Design Course Online

    ReplyDelete
  64. Hi dear,

    Thank you for this wonderful post. It is very informative and useful. I would like to share something here too.Travel portal solution is one of the popular website in India providing B2B and B2C travel portal development, white label solutions ,GDS/XML API integration services for travel related website.


    Airline Reservation System Development


    ReplyDelete
  65. This post is so useful and informative. Keep updating with more information.....
    Best CCNA Institute In Bangalore
    CCNA Institute In Bangalore

    ReplyDelete
  66. Thank you for sharing an amazing & wonderful blog. This content is very useful, informative and valuable in order to enhance knowledge. Keep sharing this type of content with us & keep updating us with new blogs. Apart from this, if anyone who wants to join Python & Advanced Excel Training institute in Delhi, can contact 9311002620 or visit our website-
    https://htsindia.com/Courses/Business-Analytics/adv-excel-training-course

    ReplyDelete
  67. Thanks for this post. It proves very informative for me. Great post to read. Visit my website to get best Information About Best IAS Coaching in Andheri.
    Best IAS Coaching in Andheri
    Top UPSC Coaching in Andheri

    ReplyDelete
  68. This post is so useful and informative. Keep updating with more information.....
    Swift Language Code
    IOS App Development

    ReplyDelete
  69. THANK YOU for this amazing and for sharing this blog with us, it is very helpful. Please keep updating us more about like this type of blog. It is the best place where you get the practical knowledge of Python if you want to get more knowledge of python you can visit Python Training here.

    ReplyDelete
  70. https://appgrouplinks.blogspot.com/2022/04/pune-whatsapp-groups.html

    ReplyDelete
  71. https://appgrouplinks.blogspot.com

    ReplyDelete
  72. https://appgrouplinks.blogspot.com/2022/04/pune-whatsapp-groups.html

    ReplyDelete
  73. https://appgrouplinks.blogspot.com/2022/04/pune-whatsapp-groups.html

    ReplyDelete
  74. https://appgrouplinks.blogspot.com/2022/04/pune-whatsapp-groups.html

    ReplyDelete
  75. https://appgrouplinks.blogspot.com/2022/04/pune-whatsapp-groups.html

    ReplyDelete
  76. Thanks for sharing the useful information about Python. If you are looking for the leading and reputed Mobile App Development Company In India, then you can go with Lucid Outsourcing Solutions. They have team of experts in various technology in Mobile App Development and always looking for a new challenges in development.

    ReplyDelete
  77. This comment has been removed by the author.

    ReplyDelete
  78. informative blog, i would like to share my knowledge on python course in satara

    ReplyDelete
  79. Enjoyed reading the article above, really explains everything in detail, its effective
    python training in hyderabad

    ReplyDelete
  80. Hi, I just completed my Python training course in Kolkata, then I found your blog. This is such a game-changer! Automating blog posts using Python and the Google Blogger API is a brilliant idea. It not only saves time but also adds a new level of efficiency to content management. Can't wait to try this out and streamline my blogging process!

    ReplyDelete

Post a Comment

Popular posts from this blog

Connect VPN via Python

Website crawl or scraping with selenium and python