MENU

#笔记#国内使用Disqus第三方评论系统

June 13, 2018 • Read: 7588 • 网络笔记

国内的多说,友言都是曾经热门的第三方评论系统,包括现在的畅言。目前还在幸存的只有畅言了,但是畅言的接入以及评论的审核都是一件麻烦的事情,唯一一个能自己拿到数据的第三方评论Valine,使用了leancloud的储存也有出现问题的时候。

Valine还是一个比较不错的国人开发的第三方评论,如果你也想搭建请访问我之前写过的文章

[post cid="1184" /]

disqus-空白网络.PNG

环境

  • 后端PHP环境支持curl扩展
  • 前端CSS/JS

源码

Github仓库:https://github.com/aihoom/disqus-php-api

将github仓库源码下载到你的PHP网站中

cd /你的网站目录
git clone https://github.com/aihoom/disqus-php-api
mv disqus-php-api/* /你的网站目录

申请API

点击申请Disqus API
取得相关的公钥(API Key)、私钥(API Secret),并填写于后端的配置文件 config.php 中。

App 设置方面,回调链接请填写 login.php 文件的绝对地址,主要的设置如下图,可根据自己情况填写。

前端设置

详细设置在https://github.com/aihoom/disqus-php-api的readme.md中

<link rel="stylesheet" href="path/to/iDisqus.min.css" />
<div id="comment"></div>
<script src="path/to/iDisqus.min.js"></script>
var disq = new iDisqus('comment', {
    forum: '你的shortname',
    api: 'http://api.你的域名/api',
    site: 'http://你的域名',
    mode: 1,
    timeout: 3000,
    init: true
});

配置参数

配置参数

ID

new iDisqus(ID, OPTIONS);
DOM 节点的 id 属性
{String}
默认:"comment"
OPTIONS

new iDisqus(ID, OPTIONS);
{Object}
api

API 地址,PHP 代码部署的网址如:http://api.fooleap.org/disqus
{String}
必填,无默认值
forum

Disqus forum 的 shortname
{String}
必填,无默认值
site

网站域名,建议填写,如:http://blog.fooleap.org
{String}
默认:location.origin
url

页面链接,一般不需要填写
{String}
默认:location.pathname + location.search
identifier

页面标识,按需填写
{String}
默认:url
title

页面标题
{String}
默认:document.title
mode

1 检测能否访问 Disqus,若能则加载 Disqus 原生评论框,超时则加载简易评论框
2 仅加载简易评论框
3 同时加载两种评论框,先显示简易评论框,Disqus 加载完成则切换至 Disqus 评论框
{Number}
默认:1
timeout

当 mode 为 1 时的超时时间
{Number}
默认:3000
toggle

当 mode 为 3 时可用,作用是切换评论框
具体用法是在网页中放置一个 Checkbox,如 <input type="checkbox" id="comment-toggle" disabled />,此项则设置为 "comment-toggle",当 Disqus 加载完时,选择框可用。
{String}
无默认值
init

是否自动初始化
{Boolean}
默认:false
autoCreate

是否自动创建 Thread,为了不创建垃圾 Thread,并不推荐设置为 true
{Boolean}
默认:false
emojiPath

Emoji 表情 PNG 图片路径
{String}
默认:"https://assets-cdn.github.com/images/icons/emoji/unicode/"
emojiList

自定义评论框内的点选 Emoji 表情,具体可看 DEMO 页面
{Object}
emojiPreview

评论预览是否支持 Emoji 短代码
{Boolean}
默认:false

Archives QR Code Tip
QR Code for this page
Tipping QR Code
Leave a Comment

11 Comments
  1. 你好 你好

    测试评论

    1. @你好???

    2. Mark Mark

      @空白网络哈哈哈哈

  2. 看着不错

  3. sgl sgl

    谢谢

  4. 说个什么好测试呢

    1. 12 12

      @不说测试下

  5. 1111111111@(哈哈)

  6. fdas fdas

    @(哈哈)

  7. ByteCat ByteCat

    目前用的这个评论就是 Disqus 的实现吗?挺好看的,我去 GitHub 学习一下 @(哈哈)

    1. @ByteCat这个评论并不是用disqus实现的,是typecho自带的。