WebFacebookLogin脸书登录验证具体内容见官⽅⽂档,这边直接上代码及测试结果
<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<script>
function statusChangeCallback(response) {  // Called with the results LoginStatus().
console.log('statusChangeCallback');
console.log(response);                  // The current login status of the person.
if (response.status === 'connected') {  // Logged into your webpage and Facebook.
testAPI();
} else {                                // Not logged into your webpage or we are unable to tell.
'into this webpage.';
}
}
function checkLoginState() {              // Called when a person is finished with the Login Button.
statusChangeCallback(response);
});
}
//STEP1: Load the SDK asynchronously
//STEP2: Init the SDK upon load
window.fbAsyncInit = function() {
FB.init({
appId      : '{app-id}',
cookie    : true,                    // Enable cookies to allow the server to access the session.
xfbml      : true,                    // Parse social plugins on this webpage.
version    : '{api-version}'// Use this Graph API version for this call.
});
statusChangeCallback(response);        // Returns the login status.
});
};
function testAPI() {                      // Testing Graph API after login.  See statusChangeCallback() for when this call is made.
console.log('Welcome!  Fetching ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
'Thanks for logging in, ' + response.name + '!';
});
}
</script>
<!-- The JS SDK Login Button -->
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>
<div id="status">
</div>
<!-- Load the JS SDK asynchronously -->
html怎么实现登录验证功能<script async defer crossorigin="anonymous" src="connect.facebook/en_US/sdk.js"></script>
</body>
</html>
如果已经登录了,测试结果如下:
注意异步加载JS SDK的写法有两种,法⼀如上:
<!-- Load the JS SDK asynchronously -->
<script async defer crossorigin="anonymous" src="connect.facebook/en_US/sdk.js"></script>
法⼆,如下代码
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s);
js.id = id;
js.src = "connect.facebook/en_US/sdk.js";//"connect.facebook/en_US/sdk/debug.js";        fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'fb-jssdk'));
其实就是⽣成如下元素

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。