disqus-php-api icon indicating copy to clipboard operation
disqus-php-api copied to clipboard

iDisqus.min.js报错

Open hellolvs opened this issue 7 years ago • 18 comments

2017-09-27 18-21-49

hellolvs avatar Sep 27 '17 10:09 hellolvs

我发现在其他用这api的网站偶尔也会报这个错,我这一直报这个错..评论一直加载中

hellolvs avatar Sep 27 '17 10:09 hellolvs

用hexo发布这个disqus包会有一些其他错误,只能每次先发文章,在把该disqus手动传到网站根目录下吗

hellolvs avatar Sep 27 '17 10:09 hellolvs

你好,www.hellolvs.com 是这个站吗?

1、昨天我有粗略看了下,请求返回的是一个文本,而不是经 PHP 处理后的结果。应该是你的 PHP 没部署好,使用这个需要用到 PHP 环境。你看到哪个站用了报错呢? 2、api 目录需要部署到 PHP 环境,前端部分(CSS、JS)应该可以直接跟你博客其他文件放一起。

fooleap avatar Sep 28 '17 00:09 fooleap

是这个,hexo应该是node.js环境,确实没弄PHP,不过我在他们配置教程中也没发现需要配置PHP环境。这俩站:http://smk17.cn/posts/104/index.html https://www.kmac007.me/2017/0917.html#more 不过他们的也不稳定啊,有时也一直加载中,有时也出现创建Thread

hellolvs avatar Sep 28 '17 02:09 hellolvs

image

这是上面第一个网站刚出的错

image

这是第二个出的错,一直加载中。 也碰到过我出的错,忘了哪个站了。

hellolvs avatar Sep 28 '17 02:09 hellolvs

  1. 后端是 PHP 写的,你上面所提到的博文只是带过,没说具体的服务器配置。
  2. http://smk17.cn/posts/104/index.html 这条链接应该是 http://smk17.cn/posts/104/,因为我的代码是根据博文链接获取评论数据,默认可以说是 location.href,smk17 博主没有在配置时,指定唯一的链接,所以会出这个问题,这个我想下有没有更好的获取评论方法。
  3. kmac007.me 这个站之前是好的,目前是同源策略问题,服务器没设置好,或者我的代码还有一定缺陷。

fooleap avatar Sep 28 '17 02:09 fooleap

所需要的PHP环境配置可不可以给个链接啊,没用过

hellolvs avatar Sep 28 '17 02:09 hellolvs

你现在是用的 VPS 吗?Nginx + PHP 还算方便,例如 https://blog.izgq.net/archives/763/

fooleap avatar Sep 28 '17 03:09 fooleap

终于配好了,是vps,用的centos系统跟ubuntu的php环境配置不太一样...非常感谢!!但是我每个页面都出现创建Thread,点提交才出现评论,正常吗

hellolvs avatar Sep 28 '17 06:09 hellolvs

也有在url后加上index.html,又需要创建thread的问题。如何指定唯一链接呢

hellolvs avatar Sep 28 '17 06:09 hellolvs

1、如果之前没用过 Disqus 的话,是正常的。 2、指定唯一连接可以在配置时,指定 url,估计得根据 Hexo 的模板。 例如:你这篇文章:https://www.hellolvs.com/inputgroup/ 值就是/inputgroup/,域名后的这段。

fooleap avatar Sep 28 '17 06:09 fooleap

又发现了问题: 1、在连不上disqus的情况下,即使配置了identifier(不同url的identifier是一样的),仍然会出现创建Thread。能连上disqus的话是OK的,不同url相同identifier可以加载同一份评论。 2、iDisqus.js有这一段代码 [

        _tip = '尝试连接 Disqus……';

        var s = d.createElement('script');
        s.src = '//'+_.opts.forum+'.disqus.com/embed.js';
        s.dataset.timestamp = Date.now();
        s.onload = function(){
            _.stat.disqusLoaded = true;
            _tip = '连接成功,加载 Disqus 评论框……'
        } 
        s.onerror = function(){
            if( _.opts.mode == 1){
                _tip = '连接失败,加载简易评论框……';
                _.getlist();
            }
        }

        var xhr = new XMLHttpRequest();
        xhr.open('GET', '//disqus.com/next/config.json?' + Date.now(), true);
        xhr.timeout = _.opts.timeout;
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                (d.head || d.body).appendChild(s);
            }
        }
        xhr.ontimeout = function () {
            xhr.abort();
            if( _.opts.mode == 1){
                _tip = '连接超时,加载简易评论框……';
                _.getlist();
            }
        }
        xhr.onerror = function() {
            if( _.opts.mode == 1){
                _tip = '连接失败,加载简易评论框……';
                _.getlist();
            }
        }
        xhr.send();](url)

在判断获取json超时之前,先从disqus加载embed.js,但是embed.js有时加载超级慢或者失败导致评论一直加载中,也就是设置的超时未生效,能把这段加载embed.js也加上超时吗?

hellolvs avatar Sep 28 '17 09:09 hellolvs

  1. 因为我是使用页面链接去获取评论数据,而不是通过 ident。等我有时间去试试相同的 ident,同时传链接和 ident,Disqus API 的数据返回情况。或者你也可以试试 https://disqus.com/api/docs/threads/listPosts/
  2. 连接存在的各种情况折腾了一阵,感觉有点乱,故没有加进太多的判断。后续打算加入 OAuth 授权,这个可能会化简,暂时不改了,目前 mode 设置为 3 时,无论如何会先加载简易评论框。

fooleap avatar Sep 28 '17 10:09 fooleap

好的,表示期待

hellolvs avatar Sep 28 '17 10:09 hellolvs

你好 我的博客也出现了js 错误 不过我使用了PHP环境, 出现的错误处是11 请问您能帮我看一下吗? 博客网址是:https://blog.99xin.me

99xin avatar Nov 06 '18 16:11 99xin

@99xin 后台权限问题,你部署 PHP 代码所在目录,当前用户必须有可写的权限。

fooleap avatar Nov 07 '18 00:11 fooleap

@99xin 后台权限问题,你部署 PHP 代码所在目录,当前用户必须有可写的权限。

我设置了chmod 777 -R /源码所在目录 但是好像还是没有解决...

99xin avatar Nov 07 '18 08:11 99xin

@99xin 我刚看了下,报错已经没有了。 你把 disq.popular() 给去掉就可以,这是以前的方法,现在已废弃。

fooleap avatar Nov 07 '18 08:11 fooleap