Discourse API を通じてトピックの最上位投稿のみを取得する

トピックのトップレベルの投稿の中から、最新の20件を取得したいと考えています。しかし、現在のように返信を再取得してフィルタリングし、20件に達するまで再帰的に処理する必要はありません。このためのフィルタは存在し、APIのどこかで見落としているだけでしょうか?

現状では、レスポンス内のストリーム配列に、投稿番号順に投稿の返信が含まれているように見えます。例えば、4件の投稿 [1, 2, 3, 4] があり、投稿1に返信した場合、ストリームは [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 クエリパラメータが追加され、この問題を解決できるようになりました。

メタの例はこちらです:https://meta.discourse.org/t/linkify-words-in-post/82193.json?filter_top_level_replies=true