使用NodeBB API创建帖子主题和回复

NodeBB

API的调用地址:

  • 主题 - /api/v3/topics/ (docs);
  • 回复 - /api/v3/topics/{tid} (docs).

通过 /api/v3/topics/ API使用Pythonrequests库创建一个主题

data = {
    "cid": int(cid),
    "title": entry.title,
    "content": '\n'.join(description),
    "tags": tags
}
headers = {'Authorization': 'Bearer {token}'.format(token=os.environ.get('NODEBB_TOKEN'))}
url = '{host}/api/v3/topics/'.format(host=os.environ.get('NODEBB_URL'))

response = requests.post(
    url=url,
    headers=headers,
    json=data
)
response.raise_for_status()

Post Comment