So, when we get a post like so:
GET /posts/13.json
We can see in the json actions_summary which contains the number of likes the post has. And you can deduce if the user I am logged in as has liked if “acted” or “can_act” is present.
"actions_summary": [
{
"id": 2,
"count": 2,
"acted": true
},
But, how do I lookup which users liked the post? We have 2 likes here, one is mine since “acted” is true. But there is one other like. How do I find out which user that is through the API? It is fine if we have to use an admin account to check.
3 个赞
Falco
(Falco)
2018 年12 月 6 日 13:22
2
As explained at How to reverse engineer the Discourse API
curl 'https://meta.discourse.org/post_action_users?id=507029&post_action_type_id=2'
3 个赞
Your link does not work.
This works for me though:
GET /post_action_users?id=13&post_action_type_id=2
This outputs
{
"post_action_users": [
{
"id": 1,
"username": "ausername",
"name": null,
"avatar_template": "/letter_avatar_proxy/v2/letter/i/{size}.png",
"post_url": null,
"username_lower": "ausername"
},
{
"id": 10,
"username": "anotherusername",
"name": null,
"avatar_template": "/letter_avatar_proxy/v2/letter/{size}.png",
"post_url": null,
"username_lower": "anotherusername"
}
]
}
Which is a list of users who liked the post with id 13
Falco
(Falco)
2018 年12 月 6 日 13:37
4
It was missing the accept header:
curl 'https://meta.discourse.org/post_action_users?id=507033&post_action_type_id=2' -H 'Accept: application/json'
3 个赞
pontus.dualdecade:
post_action_users?
you need to pass
/post_action_users.json?id=507033&post_action_type_id=2
paigen11
(Paige N)
2022 年4 月 27 日 19:09
6
您好!
我正在尝试为我们公司使用的 Discourse 论坛(https://discuss.blues.io )确定类似的事情。
我拥有员工级别的凭证,但是,当我查看已被点赞帖子的 JSON 负载时,我在 actions_summary 或 post_action_users JSON 负载中都没有看到任何指示。
例如,这个帖子 有很多回复和点赞,但是当我通过浏览器查询它时 https://discuss.blues.io/post_action_users.json?id=31&post_action_type_id=2,我得到的回应是 {"post_action_users":[]}。
也许 API 已经改变了?或者我查询的东西不对。非常感谢您的帮助。
另外还有一个后续问题:是否可以设置一个 webhook 来通知我用户点赞帖子时,并能识别出用户和帖子?我们希望为分析目的捕获这些信息。
谢谢!
1 个赞
leonardo
(Leonardo Mosquera)
2022 年5 月 18 日 16:32
10
你好 Paige!
ID 为 31 的帖子是一个用于全局置顶的小帖子操作(即 Post.find(31).action_code == 'pinned_globally.enabled'),这些帖子不能像普通帖子一样进行交互,因此无法点赞。
该主题中只有一个普通帖子,但它也没有点赞。
试试帖子 33 - 那个帖子有赞,你可以在这里看到它们的序列化:
https://discuss.blues.io/post_action_users.json?id=33&post_action_type_id=2
5 个赞
paigen11
(Paige N)
2022 年5 月 18 日 18:34
12
您好,Leonardo:
非常感谢您提供关于不同帖子类型的信息,这些信息很有用。
感谢您的回复。
此致,
Paige
2 个赞