Get number of likes for a single post?

AI 生成的摘要

In a discussion titled “Get number of likes for a single post?” under the Dev category and tagged with rest-api, mr8 initially sought a way to retrieve the like count for an individual post via the Discourse API, noting that like_count only appeared for entire topics. After some exploration, mr8 discovered the like count is available under the actions_summary field in the API response — for example, {"id":2, "count":5,"acted":true} — though this field is omitted if a post has no likes. smileBeda pointed out this behavior makes the API unreliable and noted the absence of documentation for this feature in official API docs. blake acknowledged the gap and committed to improving the API documentation, explaining it’s partially auto-generated via rspec tests using rswag. smileBeda offered to help with documentation, asking whether it’s manually written or code-generated; blake clarified it’s a hybrid approach, and shared a link to a meta topic explaining how to contribute to the API docs.

Hello,
I’m trying to get the number of likes for a single post via the API, but can’t seem to find it…

I see a like_count for the entire topic, but can’t seem to find the individual like count for each post in either /t/123.json or /posts/222.json.

I noticed that I can get a list of users who liked a post via /post_action_users.json and add them up manually, but what is the recommended way to to get the “like count” for an individual post?

Thanks!

I’m an idiot!
Found it under "actions_summary":

{"id":2,"count":5,"acted":true}

Well, hope this helps someone else!

兄弟,太感谢了!这对我帮助很大!

遗憾的是,如果帖子没有点赞,Discourse 会移除该属性。
此外,它也不在 API 文档中:Discourse API Docs, Discourse API Docs

因此,不可靠,代码会被不必要的“if property object exist”污染。
应该改进,最好是这样。

感谢您的反馈。是的,查看 API 文档,上面没有任何关于获取点赞的信息,只有关于创建点赞的信息。我将首先改进这方面的 API 文档。

非常感谢你。\n如果我能在这方面提供帮助(这是人工写的吗?!),请告诉我。\n但我怀疑你使用的是类似 PHPdoc 的东西,只是用于 Ruby,或者 Discourse 所用的任何语言?\n我没有那种语言的经验,所以如果是程序化的,我帮不了(目前还不行):P

我认为是各占一半。仍然需要人工操作,但它们是通过一个名为 rswag 的工具从 rspec 测试生成的。