user1692261
user1692261

Reputation: 1217

How to use OAuth 2.0 credentials with blogger api v3 (python requests)

I am trying to automate my blog writing a bit by using Blogger API v3.0.

I have my API_KEY and by using it I managed to access my blog like that:

import requests

APIKEY = 'XXX-YYY-ZZZ'
BLOGID = '12345678'
get_blog = 'https://www.googleapis.com/blogger/v3/blogs/{BLOGID}?key={APIKEY}'.format(BLOGID=BLOGID, APIKEY=APIKEY)
response = requests.get(get_blog)

Next I tried to create a new post:

params = {
  "kind": "blogger#post",
  "blog": {
    "id": BLOGID 
  },
  "title": "A new post",
  "content": "With <b>exciting</b> content..."
}

new_post = 'https://www.googleapis.com/blogger/v3/blogs/{blogID}/posts/?key={APIKEY}'.format(blogID=bereshitID, APIKEY=APIKEY)
response = requests.post(get_blog, params=params)

But I got an Error: {u'error': {u'status': u'PERMISSION_DENIED', u'message': u'The caller does not have permission', u'code': 403, u'errors': [{u'reason': u'forbidden', u'message': u'The caller does not have permission', u'domain': u'global'}]}}

So I figured I need to have OAuth 2.0 credentials. So I created it and now I have client_id and client_secret and I tried to add it to the params:

CLIENT_SECRET = 'ABCD-EFGH'
CLIENT_ID = '1111'

params = {
  "client_secret" : CLIENT_SECRET,
  "client_id" : CLIENT_ID,
  "kind": "blogger#post",
  "blog": {
    "id": BLOGID 
  },
  "title": "A new post",
  "content": "With <b>exciting</b> content..."
}

new_post = 'https://www.googleapis.com/blogger/v3/blogs/{blogID}/posts/?key={APIKEY}'.format(blogID=bereshitID, APIKEY=APIKEY)
response = requests.post(get_blog, params=params)

However I am still getting the error as before.

Clearly I am missing something here but I couldn't find a solution... So how should I use the OAuth 2.0 credentials correctly?

Upvotes: 2

Views: 931

Answers (1)

user1692261
user1692261

Reputation: 1217

I found this guide by Rajashekar Jangam (ImRaj90) very informative.

I followed it and managed to work with my blog using the API.

Thank you Rajashekar.

Upvotes: 1

Related Questions