I know this is an old question, but Google reveals a lot of these SO questions (this is the main result), mostly without any solid answers or answers that rely on the Github API, which doesn't seem to work very well.
I struggled to count the number of comments over the course of a few days, and also tried this API class, which seemed to crash my application with some fatal error.
After a bit more searching, I came across a link to the JSON output of the Disqus API, and after some conversation I wrote a quick function to get a comment counter:
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']; }
You need to register the application in order to get a public API key that you can do here: https://disqus.com/api/applications/
This function then simply displays the total number of comments that you can save to the database or something else.
What this function does:
The $json array returns a lot of information about the page where your comment plugin is enabled. For example:
Array ( [0] => Array ( [feed] => https:
Since the array is returned without any useful keys for the top-level array, we do array_search in the array using the column name we will know: the URL of your page, where the comment plugin ( [link] )
Then the top-level array key will be returned, in this case 0 , which we can pass back to extract the information we need from the array, such as general comments ( posts key array).
Hope this helps someone!
MrLewk
source share