[英]Unable to access notion comments via API/python
I'm trying to read the comments on a database entry in notion but I can't figure out how I need to make the request.我正在尝试阅读关于概念中数据库条目的评论,但我无法弄清楚我需要如何发出请求。
import requests
_url = 'https://api.notion.com/v1/comments'
_headers = {"Authorization": _auth,
"Notion-Version": "2021-08-16"}
_data = {'block_id': _page_id}
_results = requests.post(_url, headers=_headers, data=json.dumps(_data))
_data = _results.json()
These results I get back are something like this:我得到的这些结果是这样的:
{u'code': u'validation_error',
u'message': u'body failed validation. Fix one:\nbody.parent should be defined, instead was `undefined`.\nbody.discussion_id should be defined, instead was `undefined`.',
u'object': u'error',
u'status': 400}
I'm trying to follow the docs here https://developers.notion.com/reference/retrieve-a-comment but I'm not sure how it translates into python.我正在尝试按照此处的文档https://developers.notion.com/reference/retrieve-a-comment但我不确定它是如何转化为 python 的。
Has anyone managed to do this?有没有人设法做到这一点?
If you are reading/getting data from the API, you should use GET
, not POST
.如果您正在从 API 读取/获取数据,则应使用
GET
而不是POST
。
To translate the API to Python code, you will do something like this.要将 API 转换为 Python 代码,您需要执行如下操作。 Notice that the
block id
is a query parameter not in the request body.请注意,
block id
是不在请求正文中的查询参数。
_url = 'https://api.notion.com/v1/comments'
_headers = {"Authorization": _auth,
"Notion-Version": "2021-08-16"}
_query = {'block_id': _page_id}
_results = requests.get(_url, headers=_headers, params=_query)
_data = _results.json()
You also need to ensure that you have added the integration to the notion page.您还需要确保已将集成添加到概念页面。
Run the code, you will get the response like this, (in my case, I don't have any comments on the page).运行代码,你会得到这样的响应,(在我的例子中,我在页面上没有任何评论)。
{'object': 'list', 'results': [],
'next_cursor': None, 'has_more': False,
'type': 'comment', 'comment': {}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.