我正在尝试使用Facebook的javascript SDK登录/注销按钮(https://developers.facebook.com/docs/facebook-login/login-flow-for-web)以及Facebook的评论插件(https://developers.facebook.com/docs/plugins/comments/)。我的代码如下:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '############',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
// Facebook login button
<div class="fb-login-button" data-max-rows="1" data-size="medium"
data-show-faces="false" data-auto-logout-link="true">
</div>
// Facebook comments plugin
<div class="fb-comments" data-href="##########" data-numposts="5"
data-colorscheme="light" social="true">
</div>
这两个功能都可以单独使用,但如果用户通过单击评论框内的“使用...评论”按钮登录,则登录按钮不会更改为注销按钮。
FB.Event.subscribe提供了一种检测登录事件的机制,但当用户使用它登录时,评论插件似乎不会触发任何事件。
当用户使用评论插件登录时,有没有人知道如何让主登录按钮更改为注销按钮?
答案 0 :(得分:0)
以下是Facebook的回复:
此时此行为是设计使然。社交插件旨在覆盖我们开发人员的大多数用例,而评论插件的一般用例是未明确集成Facebook登录的网站,因此评论插件不提供登录事件。
但是,由于用户的登录只在他们尝试发布评论时触发,对于已注销的用户,您应该将您的JS SDK实现订阅到&#34; comment.create&#34;事件而不是登录事件。在这种情况下,如果需要,您可以触发刷新页面以显示&#34;注销&#34;按钮。
我确实尝试将一个刷新操作附加到comment.create事件,但该事件仅在用户实际发布评论时触发,而不是在他们登录评论插件时触发。总而言之,非常令人失望。