問題描述
使用 FB.login 的註冊流程 (Registration flow using FB.login)
I want to change Login + registration flow with FB Javascript SDK using FB.login().
Now FBML way wroks fine:
<fb:login-button registration-url="<?php echo $config["base_url"]; ?>test.php" size="small"></fb:login-button>
on clicking the button above the following code triggers the div to show registration plugin
FB.getLoginStatus(function(response) {
if (response.status === 'not_authorized') {
// show registration form
document.getElementById('reg').style.display = "block";
}
});
// registration form placed in a div
<div style="display:none;width:540px;position:relative;margin:0 auto;" id="reg">
<fb:registration fields="name,birthday,gender,location,email"
redirect uri="http://app.sunosunaao.com/test.php" width="530">
</fb:registration>
</div>
But Is there a way to show the above div once user logged in from FB.login()? Because If I use FB.login(), it directly goes to Facebook Permission page, and once connected the condition in the following function is
response.status === 'connected'
hence the registration plugin is not triggered
FB.getLoginStatus(function(response) {
if (response.status === 'not_authorized') {
// show registration form
document.getElementById('reg').style.display = "block";
}
});
Any Idea as to how i can subtitute
<fb:login-button registration-url="<?php echo $config["base_url"]; ?>test.php" size="small"></fb:login-button> with FB.login();
參考解法
方法 1:
You can attach events in your javascript code like what was described in this post here http://developers.facebook.com/blog/post/534/
FB.Event.subscribe('auth.login', function(response) {
// this code is executed after login success
});
FB.Event.subscribe('auth.logout', function(response) {
// this code is executed after logout success
});
I hope that will help.
(by Ujwal Abhishek、Wardi)