我想知道并试图找到一个Google Plus插件,比如Facebook,比如DISQUS或IntenseDebate?
有人知道是否有一个或有一个想法如何使用Google+API?
<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密钥
目前不存在官方评论插件,但您可以使用RESTAPI通过comments.list方法访问公共帖子上的评论。
这意味着,如果你通过公共活动在Google+上共享一个页面,你可以使用API列出对Google+上该活动的所有评论,然后在你的页面中呈现。然后,您可以将访问者链接到活动,从而允许他们参与对话。
我已经看到了这种技术的一些实现。这里有一个JavaScript实现,它被设计为放入一个静态HTML博客中。我不会在这里复制整个条目,因为它非常复杂,但你需要做的要点是:
- 获取API密钥以访问Google+API
- 将公共活动的ID嵌入到文档中。在链接的示例中,将其隐藏到div的类中
- 使用RESTAPI的JSONP接口来获取该活动的注释。如果一页评论就足够了,那么这就是一行了
https://www.googleapis.com/plus/v1/activities/_somePublicActivityId_/comments?key=_yourApiKey_&callback=myawesomecallback
通过回调函数将注释打印到页面中的某个位置。
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>"; }
不,Google+API目前完全是只读的,它没有像Facebook那样的评论插件。