gpt4 book ai didi

php - 我如何获得 Disqus 中的评论数?

转载 作者:可可西里 更新时间:2023-11-01 12:32:57 26 4
gpt4 key购买 nike

我想将 Disqus 评论数存储在我自己的数据库中,以便我可以按评论数对我的文章进行排序。基本上,每次在我的网站上阅读一个页面时,我都想询问 Disqus 该页面有多少条评论,然后用该计数更新数据库。

http://docs.disqus.com/help/3/似乎没有帮助。

有什么建议吗?

最佳答案

使用 disqus API 获取评论数

以下是您在开始之前需要完成的工作:

注册 Disqus API key(可选)有自己的站点来替换示例数据

注意:您使用的 URL 必须与 Disqus 中设置的 URL 相匹配。有关可靠设置的信息,请参阅 Web 集成文档。

示例 HTML

<!DOCTYPE html>
<html>
<head>
<title>Disqus Comment Counts Example</title>
</head>
<body>
<h1>Comment Counts Example</h1>
<div>
<a href="http://thenextweb.com/google/2013/05/03/fullscreen-beam-launches-first-youtube-app-for-google-glass-with-public-or-private-sharing/">
<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://thenextweb.com/google/2013/05/03/fullscreen-beam-launches-first-youtube-app-for-google-glass-with-public-or-private-sharing/"></div>
</a>
</div>
<div>
<a href="http://thenextweb.com/apps/2013/05/04/traktor-dj/">
<h2>Traktor DJ: Native Instruments remixes its impressive DJ software for iPhone</h2>
<div class="count-comments" data-disqus-url="http://thenextweb.com/apps/2013/05/04/traktor-dj/"></div>
</a>
</div>
<div>
<a href="http://thenextweb.com/video/2013/05/04/ninja-innovation-in-the-21st-century-with-gary-shapiro-of-the-consumer-electronics-association-at-tnw2013-video/">
<h2>Ninja innovation in the 21st Century with the Consumer Electronics Association&#8217;s Gary Shapiro [Video]</h2>
<div class="count-comments" data-disqus-url="http://thenextweb.com/video/2013/05/04/ninja-innovation-in-the-21st-century-with-gary-shapiro-of-the-consumer-electronics-association-at-tnw2013-video/"></div>
</a>
</div>
<button type="button" id="get-counts-button">Get Comment Counts</button>
</body>
</html>

变量:

<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var disqusPublicKey = "YOUR_PUBLIC_KEY";
var disqusShortname = "thenextweb"; // Replace with your own shortname

var urlArray = [];
$('.count-comments').each(function () {
var url = $(this).attr('data-disqus-url');
urlArray.push('thread:link='+url);
});
});
</script>

制作请求API

$('#get-counts-button').click(function () {

$.ajax({
type: 'GET',
url: 'https://disqus.com/api/3.0/threads/set.json?'+urlArray.join('&')+'&forum='+disqusShortname+'&api_key='+disqusPublicKey,
cache: false,
dataType: 'json',
success: function (result) {

for (var i in result.response) {

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

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

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

关于php - 我如何获得 Disqus 中的评论数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9149979/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com