Skip to content

Instantly share code, notes, and snippets.

@sarfata
Created March 1, 2013 21:58
Show Gist options
  • Save sarfata/5068200 to your computer and use it in GitHub Desktop.
Save sarfata/5068200 to your computer and use it in GitHub Desktop.
Google Script example on how to get the total number of comments for a disus forum
function disqusComments(cursor) {
var api_key = "YOUR_API_KEY";
var forum = "YOUR_FORUM";
var url = "https://disqus.com/api/3.0/forums/listThreads.json?api_key=" + api_key + "&forum=" + forum; //+ "&limit=100";
if (cursor) {
url = url + "&cursor=" + cursor;
}
try
{
Logger.log("Fetching data from: " + url);
var response = UrlFetchApp.fetch(url);
}
catch (e)
{
throw "Disqus API error: " + e;
}
if (response.getResponseCode() != 200)
throw "Unexpected response code from Disqus.";
var responseText = response.getContentText();
if (responseText == null || responseText == "")
throw "Empty response from Disqus:";
var data = Utilities.jsonParse(responseText);
var threads = data['response'];
var totalComments = 0;
for (var i = 0; i < threads.length; i++) {
totalComments += threads[i]['posts'];
}
Logger.log("Total number of disqus comments: " + totalComments)
if (data['cursor']['hasNext']) {
totalComments += disqusComments(data['cursor']['next']);
}
return totalComments;
}
@SalahAdDin
Copy link

Wha'ts the forum here? Is it the site name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment