<?
//========================================
// dehead(config/function/lib) Include
//========================================
include $_SERVER['DOCUMENT_ROOT']."/front/include/dehead.php";

//========================================
// Meta Tag
//========================================
$metaTitle = $metaInfo['n_band']['title'];
$metaDescription = $metaInfo['n_band']['description'];
$metaKeyword = $metaInfo['n_band']['keyword'];
$metaImage = $metaInfo['n_band']['image'];

//========================================
// header Include
//========================================
//include PATH_INCLUDE."header.php";
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<style>
</style>
</head>
<body>
	<h2>페이스북 API 최종</h2>
	<a href="javascript:;" class="fb_login">로그인</a> 
	<a href="javascript:;" class="fb_logout">로그아웃</a>
	<a href="javascript:;" class="fb_get">세션확인</a>
	</div>
	<div id="status"></div>
	
</body>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$('.fb_login').click(function(){
	FBLogin();
});
$('.fb_logout').click(function(){
	FBLogout();
});
$('.fb_get').click(function(){
	$('#status').html(FBNAME+"("+FBID+") <img src='"+FBPIC+"' />");
});

var FBID;
var FBNAME;
var FBPIC;
var FBTKN;

function statusChangeCallback(response) {
	console.log('statusChangeCallback');
	console.log(response);
	if (response.status === 'connected') {
		getAPI();
		
	} else if (response.status === 'not_authorized') {
		$('#status').text('페이스북 계정으로 로그인하세요.');
	} else {
		$('#status').text('페이스북 계정으로 로그인하세요.');
	}
}

function checkLoginState() {
	FB.getLoginStatus(function(response) {
		statusChangeCallback(response);
	});
}

window.fbAsyncInit = function() {
	FB.init({
		appId      : '280686338998871',
		cookie     : true,  // enable cookies to allow the server to access 
                        // the session
		xfbml      : true,  // parse social plugins on this page
		version    : 'v2.5' // use graph api version 2.5
	});

	FB.getLoginStatus(function(response) {
		statusChangeCallback(response);
	});
};

(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/ko_KR/sdk.js";
	fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

function getAPI() {
	FB.api('/me',
		{locale:'ko_KR', fields: 'name,email,picture,first_name,last_name,age_range,link,gender,locale,timezone,updated_time,verified'},
		function(response) {
		$('#status').text('안녕하세요 ' + response.name + '님!');
		console.log(response);
		
		FBID = response.email;
		FBNAME = response.name;
		FBPIC = response.picture.data.url;
	});
}
function FBLogin(){
	FB.login(function(response) {
		statusChangeCallback(response);
	},{scope:'public_profile,email'});
}
function FBLogout(){
	FB.logout(function(){
		location.reload();
	});
}

</script>
</html>
<?
//========================================
// quick bar Include
//========================================
//include PATH_INCLUDE."quick.php";

//========================================
// footer Include
//========================================
//include PATH_INCLUDE."footer.php";
?>