Getting who liked a post from the API

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 Mi Piace

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 Mi Piace

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

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 Mi Piace

you need to pass

/post_action_users.json?id=507033&post_action_type_id=2

Ciao!

Sto cercando di accertare una cosa simile per un forum Discourse che la mia azienda utilizza: https://discuss.blues.io

Ho credenziali a livello di staff, tuttavia, quando guardo il payload JSON per i post a cui è stato messo “mi piace”, non vedo alcuna indicazione né nei payload JSON actions_summary né in post_action_users.

Ad esempio, questo post ha molte risposte e “mi piace”, ma quando lo interrogo nel browser https://discuss.blues.io/post_action_users.json?id=31&post_action_type_id=2, ottengo {"post_action_users":[]}

Forse l’API è cambiata? O sto interrogando la cosa sbagliata. Qualsiasi aiuto è molto apprezzato.

E una domanda di follow-up: c’è un webhook che potrei potenzialmente configurare per essere avvisato quando un utente mette “mi piace” a un post, identificando l’utente e il post? Vorremmo acquisire queste informazioni a fini di analisi.

Grazie!

1 Mi Piace

Ciao Paige!

Il post con ID 31 è una piccola azione di post per fissare l’argomento a livello globale (cioè Post.find(31).action_code == 'pinned_globally.enabled'), e quei post non possono essere interagiti come i post normali, quindi non c’è modo che possa avere dei like.

C’è solo un post normale in quell’argomento, ma non ha nemmeno dei like.

Prova il Post 33: quello ha dei like e puoi vederli serializzati qui:

https://discuss.blues.io/post_action_users.json?id=33&post_action_type_id=2

5 Mi Piace

Ciao Leonardo,

Grazie mille per le informazioni sui diversi tipi di post, sono ottime informazioni da sapere.

Apprezzo la risposta.

Saluti,
Paige

2 Mi Piace