You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB

<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<button id="login" onclick="checkLoginState()">FaceBook Login</button>
<button id="login_out" onclick="loginOut()">FaceBook Login Out</button>
<div id="status">
</div>
<script src="jquery.min.js"></script>
<script>
$(document).ready(function () {
$.ajaxSetup({cache: true});
$.getScript('https://connect.facebook.net/en_US/sdk.js', function () {
FB.init({
appId: '176954776322838',
version: 'v2.8'
});
$('#loginbutton,#feedbutton').removeAttr('disabled');
FB.getLoginStatus(updateStatusCallback);
});
});
function checkLoginState() {
FB.getLoginStatus(function (response) {
statusChangeCallback(response);
});
}
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
if (response.status === 'connected') {
$("#login").text('Login Out');
// Logged into your app and Facebook.
testAPI();
} else {
FB.login(function (response) {
statusChangeCallback();
window.history.back();
}, {scope: 'public_profile,email'});
// The person is not logged into your app or we are unable to tell.
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
}
}
function loginOut() {
FB.logout(function (response) {
// Person is now logged out
});
}
function updateStatusCallback(response) {
statusChangeCallback(response);
}
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function (response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.name + '!';
});
}
</script>
</body>
</html>