Skip to content Skip to sidebar Skip to footer

Status Parameter Not Working When Using Python Blogger Api

I'm trying to use google-api-python-client 1.12.5 with Service account auth under Python 3.8. It seems to me that the when specifying the status parameter, Google responds with a 4

Solution 1:

I can reproduce this issue... Adding status=DRAFT will return 404 but any other filter is working...

  1. Tried with service account and your code: 404

  2. Tried with API Key like this result = requests.get('https://blogger.googleapis.com/v3/blogs/<blog_id>/posts?status=DRAFT&orderBy=UPDATED&alt=json&key=<api_key>'): 404

  3. Extracted "access_token" from service account (credentials.token after a call): result = requests.get('https://blogger.googleapis.com/v3/blogs/<blog_id>/posts?status=DRAFT&orderBy=UPDATED&alt=json&access_token=<extracted_service_account_token>'): 404

But very strangely if I use access_token given by "Try this API" here : https://developers.google.com/blogger/docs/3.0/reference/posts/list?apix_params={"blogId"%3A"blog_id"%2C"orderBy"%3A"UPDATED"%2C"status"%3A["DRAFT"]%2C"alt"%3A"json"} it's works !

Used that token with requests give me my blog post in draft status...

try this api + network panel

Just copy/paste raw Authorization header inside that script:

import requests

blog_id = '<blog_id>'
headers = {
    'Authorization' : 'Bearer <replace_here>'
}

# Using only Authorization header
result = requests.get(
    'https://blogger.googleapis.com/v3/blogs/%s/posts?status=DRAFT&orderBy=UPDATED&alt=json' % (blog_id),
    headers=headers
)
print(result)
# This should print DRAFT if you have at least one draft postprint(result.json()['items'][0]['status'])

# Using "access_token" param constructed with Authorization header splited to have only token
result = requests.get('https://blogger.googleapis.com/v3/blogs/%s/posts?status=DRAFT&orderBy=UPDATED&alt=json&access_token=%s' % (blog_id, headers['Authorization'][len('Bearer '):]))
print(result)
# This should print DRAFT if you have at least one draft postprint(result.json()['items'][0]['status'])

Results I have currently:

enter image description here

The bug doesn't seem to come from the library but rather from the token rights...However I also used the console normally to generate accesses like you.

To conclude I think it's either a bug or it's voluntary from Google... I don't know how long the "Try this API" token is valid but it is currently the only way I found to get the draft articles... Maybe you can try to open a bug ticket but I don't know specifically where it is possible to do that.

Post a Comment for "Status Parameter Not Working When Using Python Blogger Api"