【问题标题】:Disqus get comments countDisqus 获取评论数
【发布时间】:2013-12-12 15:33:13
【问题描述】:

我知道这似乎是一个简单的问题,但我发现没有简单的方法可以获取 ajax 页面中给定 disqus 标识符的评论计数。

我查看了他们的 API,这是一个选项,但我们正在为最终用户构建一个基于 ajax cms 的网站,强迫每个用户都这样做似乎有点乏味必须创建自己的 disqus 应用程序 API 并填写公钥和密钥才能获得 cmets 计数。此外,加载一个单独的远程 JS,返回一个完整的 JSON 对象,只是为了获取当前页面的 cmets 计数,似乎有点矫枉过正。

有一个 count.js 脚本here,但没有关于如何为 ajax 页面动态更新计数的信息。差不多...经过大量搜索,我发现了一些未记录的方法DISQUSWIDGETS.getCount()。但是,在为每个标识符调用一次后,这将停止工作。另外,这个方法还需要加载一个外部的JS来获取cmets的数量……

似乎很奇怪#cmets 数量无法更容易地提取。 cmets的数量毕竟是在页面上显示cmets之后可用的,但是我们当然不能用JS访问那个iframe。任何启示表示赞赏...

【问题讨论】:

  • Disqus 是我用过的最糟糕的服务之一。他们的 API 要么不存在,要么不工作,要么只工作一次(!?!?!)。显然DISQUS.getCommentCounts() 对他们来说太明显了,无法实施。

标签: disqus


【解决方案1】:
 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    • 2013-08-07
    • 2015-10-11
    • 2011-08-16
    • 2016-08-17
    • 1970-01-01
    相关资源
    最近更新 更多