Disqus gets comments

I know this seems like a simple question, but I found that there is no easy way to count comments for a given disqus id on ajax page.

I looked at their APIs , and this is an option, but we are creating an ajax cms-based website for end users, and it would be a little tedious to get each user to create their own disqus application APIs and fill out the public and private keys to get the number of comments. Also, it seems unnecessary to load a separate remote JS, returning the entire JSON object to get the current page count.

Here's the count.js script here, but there is no information on how to update the score dynamically for ajax pages. Well, almost ... after a lot of searching, I found the undocumented method DISQUSWIDGETS.getCount () . However, this stops working after one call for each identifier. In addition, this method also requires loading external JS to get the number of comments ...

It seems like the weird amount of #comments couldn't be pulled easier. The number of comments is available after viewing the comments on the page, but we cannot access this iframe with JS, of course. Any enlightenment appreciated ...

+4
source share
1 answer
 This is the html file which will help you to count the number of comments in a particular node in for any site which has disqus comment.

  <!DOCTYPE html>
   <html>
    <head>
      <title>Disqus Comment Counts Example</title>
    <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
   <script type="text/javascript">
   $(document).ready(function () {
   var disqusPublicKey = "?";

   var disqusShortname = "?"; // Replace with your own shortname

  var urlArray = [];

    $('.count-comments').each(function () {
      var url = $(this).attr('data-disqus-url');
      urlArray.push('link:' + url);
       });



    $('#get-counts-button').click(function () {
          $.ajax({
           type: 'GET',
               url: "https://disqus.com/api/3.0/threads/set.jsonp",
                   data: { api_key: disqusPublicKey, forum : disqusShortname, thread : urlArray },
cache: false,
dataType: 'jsonp',
success: function (result) {

  for (var i in result.response) {

    var countText = " comments";
    var count = result.response[i].posts;

    if (count == 1)
      countText = " comment";

    $('div[data-disqus-url="' + result.response[i].link + '"]').html('<h4>' + count +      countText + '</h4>');

       }
    }
    });
 });


  });
  </script>
    </head>
       <body>
    <h1>Comment Counts Example</h1>
    <div>
        <a href="#">
            <h2>Fullscreen BEAM: The first YouTube app for Google Glass comes with    public or private sharing</h2>
              <div class="count-comments" data-disqus-     url="http://www.dev.indiawaterportal.org/questions/can-using-ro-water-result-stomach-problems"></div>
        </a>
    </div>

       <button type="button" id="get-counts-button">Get Comment Counts</button>
   </body>

0
source

All Articles