如何使用 Discourse API 更新主题内容?

How can I update topic content using Discourse API?

我试过使用 PUT /t/:id 来更新主题内容但没有效果。

https://github.com/discourse/discourse_api/blob/master/lib/discourse_api/api/topics.rb

似乎无法使用 API 更新内容。我错过了什么吗?

您需要像这样提供主题别名:PUT /t/:slug/:id 如此处记录:http://docs.discourse.org/#tag/Topics%2Fpaths%2F~1t~1%7Bslug%7D~1%7Bid%7D.json%2Fput

/t/:id 端点仅在您发出 GET 请求时才有效,如此处所述:http://docs.discourse.org/#tag/Topics%2Fpaths%2F~1t~1%7Bid%7D.json%2Fget 我想这不是您想要的。

解决方法

In Discourse land, a topic it's just a bunch of posts. A topic has no body, the first post of the topic is the body.

所以,你要做的是:

  1. GET /t/:id 加上你的主题 id
  2. 解析 post_stream 并获取第一个 post,或任何您需要的。获取ID
  3. PUT /posts/:id 并使用您刚刚获得的ID,并在正文中提供post[raw]

请看这个讨论:https://meta.discourse.org/t/updating-topic-body-via-the-api/61220/5