Disqus API Comment Count Tutorial - Is there a better resource?

1,035 views
Skip to first unread message

Sarah S

unread,
Oct 2, 2013, 10:17:05 PM10/2/13
to disqu...@googlegroups.com
Hi all,

I've followed the tutorial here:
but still fail to get any kind of activity when I press the button. 

Following to the tutorial, I have:
  1. Registered an application at http://disqus.com/api/applications/
  2. Applied for a Public Key
  3. Set up an HTML Page as per the tutorial
  4. Set up my variables in the HTML Page, and then finally
  5. Added the 'Making the API Request' script to the HTML
  6. Click on button, nothing happens
Does anyone have a tutorial that starts from the very beginning to the end of this process? I have found videos where it's just bits and pieces here and I haven't found a live demo I can learn from.

Here's my code (with placeholder information(:

    <!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 = "DELETED FOR SECURITY -DISQUSPUBLICKEY";
     
var disqusShortname = "DELETED FOR SECURITY-MYDISQUSSHORTNAME"; // 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= folder/page-1.html>
               
<h2>Test Post One</h2>
               
<div class=”count-comments” data-disqus-url=http://www.mysite.com/folder/page-1.html></div>
           
</a>
       
</div>
 
<div>
           
<a href=”folder/page-2”>
               
<h2>Test Post Two</h2>
               
<div class=”count-comments” data-disqus-url=http://www.mysite.com/folder/page-2.html></div>
           
</a>
       
</div>


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

Thanks heaps,
Sar

Burak Yiğit Kaya

unread,
Oct 12, 2013, 4:25:48 PM10/12/13
to disqu...@googlegroups.com
Not sure if you've figured it out already but there was a syntax error in your code: you forgot to put the last `});` before the closing script tag for the whole `$(document).ready` thing.

Other than that it should work. I mean I tested it locally and no errors once you fix that.


--
You received this message because you are subscribed to the Google Groups "Disqus Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to disqus-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
BYK
Reply all
Reply to author
Forward
0 new messages