A
A
Alexander Pankov2017-07-11 18:09:24
API
Alexander Pankov, 2017-07-11 18:09:24

How to get the number of comments on a post in disqus in PHP?

Hello, it is necessary to receive information on the crown (for example, every hour) about the number of comments on each post on the site (sort and filter by this parameter), and so, the comments themselves are made on disqus, I find all sorts of solutions and libraries, but everywhere you need some then the thread parameter and I don’t understand at all where to get it from, how to generate it ...
Could you tell me how to get the number of comments for each post in PHP ...
Thank you in advance for your answer.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Kargin, 2017-07-11
@kgnk

See the official discus documentation. listThreads method .
The method returns a list of all discussions sorted by the date they were created. The "posts" field contains the number of comments on the thread.
The actual function itself:

// https://stackoverflow.com/a/42370431
function getDisqusCount($shortname, $articleUrl) {
        $json = json_decode(file_get_contents("https://disqus.com/api/3.0/forums/listThreads.json?forum=".$shortname."&api_key=".$YourPublicAPIKey),true);

        $array = $json['response'];
        $key = array_search($articleUrl, array_column($array, 'link'));
        return $array[$key]['posts'];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question