通过 Discourse API 获取主题中的顶级帖子

我希望能够获取某个主题下最新的 20 条顶级帖子,而无需递归地重新获取并过滤帖子回复直到凑齐 20 条。API 中是否有这样的过滤选项,只是我遗漏了?

目前看来,响应中的 stream 数组似乎包含了按帖子编号排列的帖子回复。例如,如果我有 4 条帖子 [1,2,3,4],然后对帖子 1 回复一条,stream 就会变成 [1,2,3,4,5]。此时,我判断 5 是回复 1 的唯一方法是检查该帖子本身,发现 “reply_to_post_number” => 1,然后将其过滤掉。我是否遗漏了什么?

1 个赞

That is correct. There is not a filter that can be added to the topic endpoint to get what you are after. However we do have the

which you could use to write a sql query to get what you are after. You can then save that query and hit the api endpoint for the saved query and pass it a topic_id as a param.

2 个赞

There isn’t a real way to get what you actually want out of this, because the metadata is messy, and people are messy and don’t really care about your analytics too much :wink:

2 个赞

Thanks, I will give this a shot.

我们现在有了 filter_top_level_replies=true 查询参数,它将为您处理这个问题。

这是它在 meta 上的一个示例 https://meta.discourse.org/t/linkify-words-in-post/82193.json?filter_top_level_replies=true