<script>
window.fbAsyncInit = function () {
FB.init({
appId: '<?php echo config_item('facebook_app_id'); ?>',
cookie: true, // enable cookies to allow the server to access
// the session
xfbml: true, // parse social plugins on this page
version: 'v2.2' // use version 2.2
});
FB.getLoginStatus(function (response) {
statusChangeCallback(response);
});
};
// Load the SDK asynchronously
(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.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
if (response.status === 'connected') {
// Logged into your app and Facebook.
getFbUserInfo(response);
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
document.getElementById('fbstatus').innerHTML = 'Please log ' +
'into this app.';
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
if (response.status !== 'unknown') {
document.getElementById('fbstatus').innerHTML = 'Please log ' +
'into Facebook.';
}
}
}
function getFbUserInfo(auth) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function (me) {
console.log('Successful login for: ' + me.name);
$('#fbstatus').text('Үйлчлүүлсэнд баярлалаа, ' + me.name + '!').show();
$.ajax({
type: "post",
url: "<?php echo site_url('api/auth/login'); ?>",
data: 'email=' + me.email + "&name=" + me.name + "&access=" + auth.authResponse.accessToken,
beforeSend: function () {
$('#loading').show();
alert(auth.authResponse.accessToken);
}
}).done(function (data) {
$('#loading').hide('slow');
alert(data);
});
});
}
$(document).ready(function () {
// setTimeout(function () {
// $('.fb-login-button').show();
// }, 2000);
});
</script>
No comments:
Post a Comment