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.
81 lines
2.0 KiB
81 lines
2.0 KiB
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Facebook Login JavaScript Example</title>
|
|
<meta charset="UTF-8">
|
|
</head>
|
|
<body>
|
|
|
|
<button id="login" onclick="fbLogin()">FaceBook Login</button>
|
|
<button id="login_out" onclick="fbLoginOut()">FaceBook Login Out</button>
|
|
<div id="status">
|
|
</div>
|
|
|
|
<script src="jquery.min.js"></script>
|
|
|
|
<script>
|
|
|
|
// Facebook JavaScript SDK
|
|
$(document).ready(function () {
|
|
$.ajaxSetup({cache: true});
|
|
$.getScript('https://connect.facebook.net/en_US/sdk.js', function () {
|
|
FB.init({
|
|
appId: '176954776322838',
|
|
version: 'v3.0'
|
|
});
|
|
});
|
|
});
|
|
|
|
// Facebook Login
|
|
function fbLogin() {
|
|
FB.getLoginStatus(function (response) {
|
|
if (response.status === 'connected') {
|
|
fbCallInfo(response);
|
|
} else {
|
|
FB.login(function (response) {
|
|
if (response.status === 'connected'){
|
|
fbCallInfo(response);
|
|
}
|
|
}, {scope: 'public_profile,email'});
|
|
}
|
|
});
|
|
}
|
|
|
|
// Facebook LoginOut
|
|
function fbLoginOut() {
|
|
FB.getLoginStatus(function (response) {
|
|
console.log(response);
|
|
if (response.status === 'connected') {
|
|
FB.logout(function (response) {
|
|
console.log('login out');
|
|
// Person is now logged out
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
// send info to server
|
|
function fbCallInfo(response) {
|
|
$.ajax({
|
|
url: '',
|
|
type: 'post',
|
|
ContentType: 'json',
|
|
data: response,
|
|
dateTyep: 'json',
|
|
success: function (data, status) {
|
|
if (status == 'success') {
|
|
console.log(data);
|
|
} else {
|
|
console.log(status);
|
|
}
|
|
},
|
|
error: function (xhr, error) {
|
|
console.log(error);
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
|
|
</body>
|
|
</html> |