gpt4 book ai didi

web - 获取 DISQUS 评论数

转载 作者:行者123 更新时间:2023-12-03 13:20:36 28 4
gpt4 key购买 nike

我正在尝试从我的 comics website 上的漫画中获取评论数.例如,漫画 id 66 有 2 条评论。我想获得该计数并将其显示在另一页上。到目前为止,当我遵循下面的 disqus 指南时,它给了我一个带有评论的漫画链接,但没有给我全部评论。

DISQUS says...

Append #disqus_thread to the href attribute in your links. This will tell Disqus which links to look up and return the comment count. For example: <a href="http://foo.com/bar.html#disqus_thread">Link</a>.



但是,如果我的 URL 字符串是这样的,我将如何获得该计数:
<a href=".?action=viewimage&site=comics&id=66">Link</a>
所以我的问题是:
  • 我将在哪里附加 #disqus_thread ?
  • 如何从那个漫画 URL 中获取评论数并在另一页上显示这些评论总数?
  • 最佳答案

    此处示例:http://help.disqus.com/customer/portal/articles/1131783-tutorial-get-comment-counts-with-the-api

    变量

    <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 = [];
    });
    </script>

    var urlArray = [];
    //...continued from above

    $('.count-comments').each(function () {
    var url = $(this).attr('data-disqus-url');
    urlArray.push('link:' + url);
    });

    发出 API 请求
    $('#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>');

    }
    }
    });
    });

    关于web - 获取 DISQUS 评论数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16075393/

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