我正在尝试编写一个 facebook 登录按钮。以下是我的 facebook javascript。一切顺利(即弹出窗口出现,facebook 登录提示等),直到我通过 facebook 应用程序成功登录,行“alert('Login Failed!');” 正在执行。这是由于 response.authResponse != 1。有人可以帮我吗?
<div id="fb-root"></div>
<script type="text/javascript">
//<![CDATA[
window.fbAsyncInit = function() {
FB.init({
appId : 'I placed my app id here', // App ID
channelURL : '', // Channel File, not required so leave empty
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
};
// logs the user in the application and facebook
function fblogin(){
FB.getLoginStatus(function(r){
if(r.status === 'connected'){
window.location.href = 'fbconnect.php';
}else{
FB.login(function(response) {
if(response.authResponse) {
//if (response.perms)
alert('Success!');
window.location.href = 'fbconnect.php';
} else {
alert('Login Failed!');
// user is not logged in
}
},{scope:'email'}); // which data to access from user profile
}
});
}
// Load the SDK Asynchronously
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
//]]>
</script>
这是我的登录按钮
echo '<a href=# onclick="fblogin();">Facebook Login</a>';