페이스북 적용중
This commit is contained in:
@ -187,8 +187,7 @@ if ($w == 'c') // 댓글 입력
|
|||||||
|
|
||||||
$facebook = new Facebook(array(
|
$facebook = new Facebook(array(
|
||||||
'appId' => $config['cf_facebook_appid'],
|
'appId' => $config['cf_facebook_appid'],
|
||||||
'secret' => $config['cf_facebook_secret'],
|
'secret' => $config['cf_facebook_secret']
|
||||||
'cookie' => true
|
|
||||||
));
|
));
|
||||||
|
|
||||||
$user = $facebook->getUser();
|
$user = $facebook->getUser();
|
||||||
@ -200,7 +199,7 @@ if ($w == 'c') // 댓글 입력
|
|||||||
'message' => stripslashes($wr_content),
|
'message' => stripslashes($wr_content),
|
||||||
'name' => $wr_subject,
|
'name' => $wr_subject,
|
||||||
'link' => $link,
|
'link' => $link,
|
||||||
'description' => stripslashes($wr['wr_content'])
|
'description' => stripslashes(strip_tags($wr['wr_content']))
|
||||||
);
|
);
|
||||||
$facebook->api('/me/feed/', 'post', $attachment);
|
$facebook->api('/me/feed/', 'post', $attachment);
|
||||||
//$errors = error_get_last(); print_r2($errros); exit;
|
//$errors = error_get_last(); print_r2($errros); exit;
|
||||||
|
|||||||
@ -22,20 +22,44 @@ $g4['title'] = '페이스북 콜백';
|
|||||||
include_once(G4_PATH.'/head.sub.php');
|
include_once(G4_PATH.'/head.sub.php');
|
||||||
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
|
|
||||||
|
$access_token = $facebook->getAccessToken();
|
||||||
|
|
||||||
|
$appid = $config['cf_facebook_appid'];
|
||||||
|
|
||||||
|
setcookie('fbs_'.$appid, 1, G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||||
|
setcookie('fbs_'.$appid.'_code', $_SESSION['fb_'.$appid.'_code'], G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||||
|
setcookie('fbs_'.$appid.'_access_token', $_SESSION['fb_'.$appid.'_access_token'], G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||||
|
setcookie('fbs_'.$appid.'_user_id', $_SESSION['fb_'.$appid.'_user_id'], G4_SERVER_TIME + 86400 * 31, '/', G4_COOKIE_DOMAIN);
|
||||||
|
|
||||||
|
sql_query(" update {$g4['member_table']} set mb_facebook_token = '{$access_token}' where mb_id = '{$member['mb_id']}' ", true);
|
||||||
|
|
||||||
$g4_sns_url = G4_SNS_URL;
|
$g4_sns_url = G4_SNS_URL;
|
||||||
|
|
||||||
echo <<<EOT
|
echo <<<EOT
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
$(function() {
|
||||||
var opener = window.opener;
|
var opener = window.opener;
|
||||||
opener.$("#facebook_icon").attr("src", "{$g4_sns_url}/icon/facebook_on.png");
|
opener.$("#facebook_icon").attr("src", "{$g4_sns_url}/icon/facebook_on.png");
|
||||||
opener.$("#facebook_checked").attr("disabled", false);
|
opener.$("#facebook_checked").attr("disabled", false);
|
||||||
opener.$("#facebook_checked").attr("checked", true);
|
opener.$("#facebook_checked").attr("checked", true);
|
||||||
//alert("페이스북 승인이 되었습니다.");
|
//alert("페이스북 승인이 되었습니다.");
|
||||||
window.close();
|
window.close();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
EOT;
|
EOT;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
echo <<<EOT
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
alert("페이스북 승인이 되지 않았습니다.");
|
||||||
|
window.close();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
EOT;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
include_once(G4_PATH.'/tail.sub.php');
|
include_once(G4_PATH.'/tail.sub.php');
|
||||||
|
|||||||
@ -20,7 +20,7 @@ require '../src/facebook.php';
|
|||||||
// Create our Application instance (replace this with your appId and secret).
|
// Create our Application instance (replace this with your appId and secret).
|
||||||
$facebook = new Facebook(array(
|
$facebook = new Facebook(array(
|
||||||
'appId' => '119146498278078',
|
'appId' => '119146498278078',
|
||||||
'secret' => '311e0d6ff8ff43cfe0e75fe82d71777c',
|
'secret' => '6ffd7e325e2b4fbd83a2eebf9c6f33f9',
|
||||||
));
|
));
|
||||||
|
|
||||||
// Get User ID
|
// Get User ID
|
||||||
@ -82,6 +82,9 @@ $naitik = $facebook->api('/naitik');
|
|||||||
</div>
|
</div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
|
<h3>PHP Cookie</h3>
|
||||||
|
<pre><?php print_r($_COOKIE); ?></pre>
|
||||||
|
|
||||||
<h3>PHP Session</h3>
|
<h3>PHP Session</h3>
|
||||||
<pre><?php print_r($_SESSION); ?></pre>
|
<pre><?php print_r($_SESSION); ?></pre>
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,8 @@
|
|||||||
require '../src/facebook.php';
|
require '../src/facebook.php';
|
||||||
|
|
||||||
$facebook = new Facebook(array(
|
$facebook = new Facebook(array(
|
||||||
'appId' => '344617158898614',
|
'appId' => '119146498278078',
|
||||||
'secret' => '6dc8ac871858b34798bc2488200e503d',
|
'secret' => '6ffd7e325e2b4fbd83a2eebf9c6f33f9',
|
||||||
));
|
));
|
||||||
|
|
||||||
// See if there is a user from a cookie
|
// See if there is a user from a cookie
|
||||||
@ -24,6 +24,9 @@ if ($user) {
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html xmlns:fb="http://www.facebook.com/2008/fbml">
|
<html xmlns:fb="http://www.facebook.com/2008/fbml">
|
||||||
<body>
|
<body>
|
||||||
|
<h3>PHP Cookie</h3>
|
||||||
|
<pre><?php print_r($_COOKIE); ?></pre>
|
||||||
|
|
||||||
<?php if ($user) { ?>
|
<?php if ($user) { ?>
|
||||||
Your user profile is
|
Your user profile is
|
||||||
<pre>
|
<pre>
|
||||||
|
|||||||
@ -3,44 +3,63 @@ if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
|
|||||||
|
|
||||||
if (!$is_member) return;
|
if (!$is_member) return;
|
||||||
if (!$config['cf_facebook_use']) return;
|
if (!$config['cf_facebook_use']) return;
|
||||||
|
|
||||||
include_once(G4_SNS_PATH."/facebook/src/facebook.php");
|
|
||||||
|
|
||||||
|
include_once(G4_SNS_PATH."/facebook/src/facebook.php");
|
||||||
$facebook = new Facebook(array(
|
$facebook = new Facebook(array(
|
||||||
'appId' => $config['cf_facebook_appid'],
|
'appId' => $config['cf_facebook_appid'],
|
||||||
'secret' => $config['cf_facebook_secret']
|
'secret' => $config['cf_facebook_secret']
|
||||||
));
|
));
|
||||||
|
|
||||||
$user = $facebook->getUser();
|
$user = $facebook->getUser();
|
||||||
//echo $token = $facebook->getAccessToken();
|
|
||||||
|
|
||||||
// CAABsXPS0wr4BAIasoXNLyI3Hg6Lqg8Qmze4vrLi2sBhenwe9Sx3qNu6hHRDGiKTVI6sDys3kmhP1B9kSoyfriZBMeTU5VEbJir8rc7QnWbyUZAZAijwd4UvPrJZCQTR4Y2fJTHVUCRILRir5Qqfs
|
|
||||||
|
|
||||||
//$user = $facebook->getUser();
|
|
||||||
//$facebook->setAccessToken("CAABsXPS0wr4BAIasoXNLyI3Hg6Lqg8Qmze4vrLi2sBhenwe9Sx3qNu6hHRDGiKTVI6sDys3kmhP1B9kSoyfriZBMeTU5VEbJir8rc7QnWbyUZAZAijwd4UvPrJZCQTR4Y2fJTHVUCRILRir5Qqfs");
|
|
||||||
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
try {
|
try {
|
||||||
$user_profile = $facebook->api('/me');
|
$user_profile = $facebook->api('/me');
|
||||||
|
|
||||||
$access_token = $facebook->getAccessToken();
|
|
||||||
sql_query(" update {$g4['member_table']} set mb_facebook_token = '{$access_token}' where mb_id = '{$member['mb_id']}' ", true);
|
|
||||||
|
|
||||||
} catch (FacebookApiException $e) {
|
} catch (FacebookApiException $e) {
|
||||||
error_log($e);
|
error_log($e);
|
||||||
$user = null;
|
$user = null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($member['mb_facebook_token']) {
|
$appid = $config['cf_facebook_appid'];
|
||||||
$facebook->setAccessToken($member['mb_facebook_token']);
|
$secret = $config['cf_facebook_secret'];
|
||||||
try {
|
$access_token = $_COOKIE['fbs_'.$appid.'_access_token'];
|
||||||
$user_profile = $facebook->api('/me');
|
|
||||||
//print_r2($user_profile);
|
$graph_url = "https://graph.facebook.com/oauth/access_token?client_id=$appid&client_secret=$secret&grant_type=client_credentials";
|
||||||
$user = $facebook->getUser();
|
$access_token = file_get_contents($graph_url);
|
||||||
} catch (FacebookApiException $e) {
|
|
||||||
error_log($e);
|
if($access_token){
|
||||||
$user = null;
|
|
||||||
|
$graph_url = "https://graph.facebook.com/oauth/access_token_info?client_id=$appid&" . $access_token;
|
||||||
|
$access_token_info = json_decode(file_get_contents($graph_url));
|
||||||
|
|
||||||
|
function nonceHasBeenUsed($auth_nonce) {
|
||||||
|
// Here you would check your database to see if the nonce
|
||||||
|
// has been used before. For the sake of this example, we'll
|
||||||
|
// just assume the answer is "no".
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nonceHasBeenUsed($access_token_info->auth_nonce) != true) {
|
||||||
|
if ($result = @file_get_contents("https://graph.facebook.com/me/?".$access_token)) {
|
||||||
|
$result = json_decode($result, true);
|
||||||
|
print_r2($result);
|
||||||
|
$user = $result['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if ($result = @file_get_contents("https://graph.facebook.com/me/?access_token=".$access_token)) {
|
||||||
|
$result = json_decode($result, true);
|
||||||
|
|
||||||
|
print_r2($result);
|
||||||
|
//echo $_SESSION['uid'] = $result['id'];
|
||||||
|
//if ($result = @file_get_contents("https://graph.facebook.com/{$result['id']}/accounts/test-users?installed=true&name={$result['name']}&locale={$result['locale']}&permissions=read_stream&method=post&access_token=".$access_token)) {
|
||||||
|
if ($result = @file_get_contents("https://graph.facebook.com/{$result['id']}/accounts/test-users?access_token=".$access_token)) {
|
||||||
|
$result = json_decode($result, true);
|
||||||
|
print_r2($result);
|
||||||
|
$user = $result['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@ -53,7 +72,7 @@ if ($user) {
|
|||||||
echo '<input type="checkbox" name="facebook_checked" id="facebook_checked" '.($member['mb_facebook_checked']?'checked':'').' value="1">';
|
echo '<input type="checkbox" name="facebook_checked" id="facebook_checked" '.($member['mb_facebook_checked']?'checked':'').' value="1">';
|
||||||
echo '<img src="'.G4_SNS_URL.'/icon/facebook_on.png" id="facebook_icon">';
|
echo '<img src="'.G4_SNS_URL.'/icon/facebook_on.png" id="facebook_icon">';
|
||||||
} else {
|
} else {
|
||||||
$facebook_url = $facebook->getLoginUrl(array("redirect_uri"=>G4_SNS_URL."/facebook/callback.php", "scope"=>"user_website,publish_stream,read_stream,offline_access", "display"=>"popup"));
|
$facebook_url = $facebook->getLoginUrl(array("redirect_uri"=>G4_SNS_URL."/facebook/callback.php", "scope"=>"publish_stream,read_stream,offline_access", "display"=>"popup"));
|
||||||
|
|
||||||
echo '<input type="checkbox" name="facebook_checked" id="facebook_checked" disabled value="1">';
|
echo '<input type="checkbox" name="facebook_checked" id="facebook_checked" disabled value="1">';
|
||||||
echo '<a href="'.$facebook_url.'" id="facebook_url" onclick="return false;"><img src="'.G4_SNS_URL.'/icon/facebook_'.($user?'on':'off').'.png" id="facebook_icon">';
|
echo '<a href="'.$facebook_url.'" id="facebook_url" onclick="return false;"><img src="'.G4_SNS_URL.'/icon/facebook_'.($user?'on':'off').'.png" id="facebook_icon">';
|
||||||
|
|||||||
Reference in New Issue
Block a user