如何获取 Disqus 中的评论数?
我想将 Disqus 评论计数存储在我自己的数据库中,以便我可以按评论计数对我的文章进行排序。基本上,每次在我的网站上阅读某个页面时,我都会询问 Disqus 该页面有多少条评论,然后用该计数更新数据库。
http://docs.disqus.com/help/3/ 似乎没有帮助。
有什么建议吗?
I'd like to store the Disqus comment count on my own database, so that I can sort my articles by comment count. Basically, every time a page is read on my site, I'd like to ask Disqus how many comments that certain page has, then update the database with that count.
http://docs.disqus.com/help/3/ doesn't seem to be helpful.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 disqus API 获取评论计数
在开始之前,您需要完成以下操作:
注册 Disqus API 密钥< /a>
(可选)使用您自己的站点来替换示例数据
注意:您使用的 URL 必须与 Disqus 中设置的 URL 匹配。有关可靠设置的信息,请参阅 Web 集成文档。
HTML 变量示例
:
创建请求 API
Get comment counts with disqus API
Here's what you'll need to have done before starting:
Register for a Disqus API key
(optional) Have your own site to replace the example data
NOTE: The URL you use must match what's set as the URL in Disqus. See Web Integration docs for information on setting this up reliably.
Example HTML
Variables:
Making the Request API
Disqus 具有 Web API,允许开发人员在自己的应用程序内与 Disqus 数据进行通信。
http://disqus.com/api/docs/
http://disqus.com/api/docs/forums/listThreads/
您也可以使用 http://disqus.com/api/console/ 来测试 api
我使用 https://github.com/disqus/disqus-php
Disqus have web api which allows developers to communicate with Disqus data from within their own applications.
http://disqus.com/api/docs/
http://disqus.com/api/docs/forums/listThreads/
Also you can use http://disqus.com/api/console/ to test api
I use https://github.com/disqus/disqus-php
我用它来获取评论计数:
http://help.disqus.com/customer/ Portal/articles/565624
它更新了您在页面中设置的链接:
第二篇文章
链接“第二篇文章”的内容将替换为评论数。
即“22条评论”。比使用 ajax 更新你的数据库的评论数。
I used this to get the comment count:
http://help.disqus.com/customer/portal/articles/565624
It's updates a link you set in page:
Second article
The content of the link 'Second article' will be replaced with the comment count.
i.e "22 Comments". Than use ajax to update you're db with the comment count.
我知道这是一个老问题,但谷歌提出了很多这样的问题(这是最重要的结果),大多数都没有任何可靠的答案或依赖于 Github API 的答案,但它似乎工作得不太好。
几天来我一直在努力获取评论计数,并且还尝试了该 API 类,该类似乎因一些致命错误而导致我的应用程序崩溃。
经过更多搜索后,我发现了 Disqus API 的 JSON 输出的链接,经过一番尝试后,我编写了一个快速函数来获取评论计数:
您需要注册一个应用程序来获取您的公共 API密钥,您可以在此处执行此操作: https://disqus.com/api/applications/
这然后函数将只输出评论总数然后您可以将其存储在数据库或其他任何位置。
此函数的作用:
$json
数组返回有关评论插件所在页面的大量信息。例如:因为数组返回时没有任何有用的顶级数组键,所以我们通过列名称键对数组执行
array_search
,我们将知道:评论插件所在的页面 URL (>[link]
)这将返回顶级数组键,在本例中为
0
,然后我们可以将其传回以从数组中提取我们想要的信息,例如总数评论(数组键posts
)。希望这对某人有帮助!
I know this is an old question, but Google turns up plenty of these SO questions (this being the top result), mostly without any solid answers or answers which rely on the Github API which doesn't seem to work very well.
I had been struggling to get the comment count for days, and also tried that API class which seemed to crash my application with some fatal error.
After a bit more searching, I came across a link to the JSON output of the Disqus API, and after some playing around, I wrote a quick function to get the comment count:
You'll need to register an application to get your public API key, which you can do here: https://disqus.com/api/applications/
This function will then just output the total number of comments which you can then store in the database or whatever.
What this function does:
The
$json
array returns much information about the page your comment plugin is on. For example:Because the array returns without any useful top level array keys, we do an
array_search
on the array by a column name key which we will know: your page URL where the comments plugin is ([link]
)This will then return the top level array key, in this case
0
which we can then pass back to extract the information we want from the array, such as the total comments (array keyposts
).Hope this helps someone!