Get number of likes for a single post?

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!

2 个赞

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

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

Well, hope this helps someone else!

16 个赞

Love you man! that helps me a lot!

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

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

1 个赞

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

1 个赞

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

1 个赞

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

1 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.