2013-11-27 4 views
4

나는 이것이 간단한 질문처럼 보인다고 알고있다. 그러나 나는 아약스 페이지에서 주어진 disqus 식별자에 대한 코멘트 카운트를 얻는 간단한 방법이 없다는 것을 발견했다.Disqus가 카운트를 얻는다

API을 보았습니다.이 옵션이 있지만 최종 사용자를 위해 ajax cms 기반 웹 사이트를 구축하고 있으며 각 사용자가 자신의 웹 사이트를 만들어야하는 것은 약간 지루한 것처럼 보입니다. 자신의 disqus 응용 프로그램 API를 작성하고 공개 및 비밀 키를 채우기 만하면 의견 수를 얻을 수 있습니다. 게다가, 별도의 원격 JS를로드하고, 전체 JSON 객체를 반환하고, 현재 페이지 주석 수를 얻는 것은 과도한 것으로 보인다.

count.js 스크립트 here이 있지만, 아약스 페이지 수를 동적으로 업데이트하는 방법에 대한 정보는 없습니다. 글쎄요 ... 많은 검색을 한 후에 문서화되지 않은 방법을 발견했습니다 DISQUSWIDGETS.getCount(). 그러나 각 식별자를 한 번 호출하면 작동이 멈 춥니 다. 게다가,이 방법은 주석 카운트를 얻기 위해 외부 JS를 로딩해야한다.

이상한 #comments 금액을 쉽게 추출 할 수없는 것 같다. 댓글의 양은 페이지에 댓글을 표시 한 후에 사용할 수 있지만 JS로 당연히 iframe에 액세스 할 수 없습니다. 모든 혁신적 기능은

+0

Disqus에 내가 지금까지 사용했던 최악의 서비스 중 하나입니다 ... 감사합니다. API가 존재하지 않거나 작동하지 않거나 한 번만 작동합니다 (!?!?!). 명백하게'DISQUS.getCommentCounts()'는 구현하기에는 너무 명백했습니다. – AJB

답변

0
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> 

관련 문제