Blogger API examples


API helps to automate.

If you have a blog with 10 posts then no problem to manage it but if you see your site growing. Then it can become a whole problem for management of 100 or 1000 pages. If many people are posting at the same time and you need to analyse content then you automate it with an API. Or you need to publish 100 or 1000 articles written in DOC files in a Blog post. Or delete certain posts that did not contain correct content.






Blogger API docs

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


Activate blogger API

https://console.cloud.google.com/apis/api/blogger.googleapis.com/





Create key and login Credentials json file for blogger desktop api.

https://console.cloud.google.com/apis/credentials?project=administratieve-medewerker&supportedpurview=project


See examples for client and blogger

https://github.com/googleapis/google-api-python-client/tree/main/samples



Then if you would like to insert something



https://google-api-client-libraries.appspot.com/documentation/blogger/v3/python/latest/blogger_v3.posts.html#insert


Example to download posts from blogger and save this information in Django objects in the database.


https://raw.githubusercontent.com/sergejdergatsjev/PageAdmin/master/importfromblogger.py



Update Instance Method documentation


https://google-api-client-libraries.appspot.com/documentation/blogger/v3/python/latest/blogger_v3.posts.html#update


Example Update



service, flags = sample_tools.init(args, 'blogger', 'v3', __doc__, __file__,
scope='https://www.googleapis.com/auth/blogger')
posts = service.posts()
body = {}
body["content"] = job.raw_text
body["url"] = job.url
body["title"] = job.title
body["kind"] = "blogger#post"
body["blog"] = {"id": job.blogger_blog_id}
body["id"] = job.blogger_post_id
body["selfLink"] = job.blogger_selfLink
request = posts_service.update(blogId=job.blogger_blog_id, postId=job.blogger_post_id, body=body)

request.execute() # Build and execute HTTPS request


Troubleshooting

We had a problem with limits so set a timer sleep to slow down code a bit.

10,000 request (list/search/get) per day; with the limit of 100 request per 100 second for each unique IP address.


googleapiclient.errors.HttpError: <HttpError 429 when requesting https://blogger.googleapis.com/v3/blogs/5850314242212352975/posts/2110009753294105544?alt=json returned "Quota exceeded for quota metric 'Queries' and limit 'Queries per minute per user' of service 'blogger.googleapis.com' for consumer 'project_number:710892222816'.". Details: "[{'message': "Quota exceeded for quota metric 'Queries' and limit 'Queries per minute per user' of service 'blogger.googleapis.com' for consumer 'project_number:710892222816'.", 'domain': 'global', 'reason': 'rateLimitExceeded'}]">

Comments