我正在开设一个测试页面,以确保Facebook登录按钮功能正确。
当用户登录并注销FB时,我让FB按钮正常工作。但我不知道如何让我的网站标题更新以切换登录/注销链接。
在FB登录/注销后,我使用与常规登录/注销时相同的所有数据更新站点的会话,但由于某种原因,标题不会在那里更新。
知道怎么解决吗?仅供参考我在这里测试这些东西:http://www.comehike.com/test_fb_connect.php
答案 0 :(得分:1)
那么,为此您必须使用Facebook的Javascript API来检测用户何时登录或注销,然后执行AJAX请求以更新标头。这将通过FB.Event.subscribe完成,如下面的代码片段所示:
window.fbAsyncInit = function() {
FB.init({
appId : 'YOURAPPID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
channelUrl : 'http://www.yourdomain.com/channel.html', // Custom Channel URL
oauth : true //enables OAuth 2.0
});
// retrieve the login status.
FB.getLoginStatus(function(response) {
if (response.authResponse) update_user_is_connected();
else update_user_is_not_connected();
});
// This will be triggered as soon as the user logs into Facebook (through your site)
FB.Event.subscribe('auth.login', function(response) {
// Here you would update your header.
update_user_is_connected();
});
};
您可以在此处详细了解FB.Event.subscribe:http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/