是否有谷歌+评论插件?(类似于Facebook社交评论、DISQUS或IntenseDebate)?

4

我在想是否有类似Facebook插件的Google Plus插件,例如DISQUS或IntenseDebate?

有没有人知道是否有这样的插件或者有没有使用Google+ API制作这样的插件的想法呢?

3个回答

3
<script src="https://apis.google.com/js/plusone.js">
</script>
<div class="g-comments"
    data-href="http://stackoverflow.com"
    data-width="580"
    data-first_party_property="BLOGGER"
    data-view_type="FILTERED_POSTMOD">
</div>

https://jsfiddle.net/fdyuhp90/1/

无需API密钥


我一直在尝试实现这个功能,但没有成功。将代码粘贴到HTML文件中并将href参数更改为window.location后,评论框可以正常加载,但我无法添加任何评论。控制台显示请求/_/scs/apps-static/_/js/k=oz.comments_widget.en.50uyNOSkHIA.O/m=c_b/rt=j/sv=1/d=1/ed=1/am=Ag/rs=AGL…时出现各种POST错误。我也无法在您的jsfiddle中添加评论。这种方法还有效吗?如果不是,是否有其他简单明了的解决方案? - Mikolaj

2
目前还没有官方的评论插件,但是您可以使用REST API通过comments.list方法访问在公共帖子上发表的评论。
这意味着,如果您通过公共活动在Google+上分享一个页面,您可以使用API列出在Google+上对该活动发表的所有评论,然后在您的页面中呈现它们。然后,您可以链接访问者到该活动,从而允许他们参与对话。
我看到过一些这种技术的实现。这里 是一个JavaScript实现,旨在嵌入静态HTML博客中。我不会在这里重复整个条目,因为它相当复杂,但您需要做的要点是:
  1. 获取API密钥以访问Google+ API
  2. 将公共活动的ID嵌入到您的文档中。在链接的示例中,将其存储在div元素的类中。
  3. 使用REST API的JSONP接口获取该活动的评论。如果一页评论就足够了,这只需要一行代码。

https://www.googleapis.com/plus/v1/activities/_somePublicActivityId_/comments?key=_yourApiKey_&callback=myawesomecallback

  1. From your callback function print the comments somewhere in the page.

    function myawesomecallback(resposneJson) {
      var activity = resposneJson.items[0].inReplyTo[0];
      var comments = resposneJson.items;
    
      //find element to insert into
      var insertionElements = document.getElementsByClassName('g-comments-for ' + activity.id);
      var insertionElement = insertionElements[0];
    
      var newContents = "";
      for(i=0; i<comments.length; i++) {
        var actor = comments[i].actor;
    
        var commentBody = comments[i].object.content;
    
        //do the insertion
        newContents += "<dt><a href='" + actor.url + 
          "'><img src='" + actor.image.url + "' /></a></dt>" + 
          "<dd><a href='" + actor.url + "'>" + actor.displayName + 
          "</a>: " + commentBody + "</dd>";
      }
      insertionElement.innerHTML = "<dl>" + newContents + 
        "</dl> <p class='g-commentlink'>Please comment on the <a href='" + 
        activity.url + "'>Google+ activity</a></p>";   
    }
    

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接