你为什么不使用注册插件。它将为您节省大量工作https://developers.facebook.com/docs/plugins/registration/
如果您想要自定义表单。您必须获得用户的许可并获取他的详细信息。您可以使用以下代码:
<div id="fb-root"></div>
<script src="https://connect.facebook.net/en_US/all.js"></script>
FB.init({appId: 'XXXXXXXXXXXXX',status : true,xfbml : true, cookie: true ,oauth : true});
function login(){
FB.getLoginStatus(function(response) {
// checks if user already authorized
if (response.status === 'connected') {
FB.api('me?fields=id,name,email', function(user) {
if(user != null) {
username = user.name;
uid = user.id;
email = user.email;
}
});
} else {
// If user is not authorized call FB.login for pop up window for authorization , scope defines list of persmission requested with user
FB.login(function(response) {
if (response.authResponse.accessToken) {
FB.api('me?fields=id,name,email', function(user) {
if(user != null) {
username = user.name;
uid = user.id;
email = user.email;
}
})
}
}, {scope:'email'});
}
});
}
按下按钮即可调用 login()。