oAuth v2를 사용하는 다른 방법이 있습니다. 이는 페이스 북 문서에 설명되어 있지만 여러 페이지로 나누어 져 있으므로 이해하기 쉽지 않습니다.
먼저 앱의 '고급 매개 변수'에 '캔버스 용 OAuth 2.0'플래그를 활성화해야합니다.
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
$data = parse_signed_request($_REQUEST["signed_request"], <your facebook app api secret>);
if (empty($data["user_id"]) && !isset($_REQUEST['redir'])) {
// The user isn't authenticated
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=" .
<your facebook app id> . "&redirect_uri=" .
urlencode('http://apps.facebook.com/<yourapp>/?redir=1');
echo("<script> top.location.href='" . $auth_url . "'</script>");
die;
}
// Here the user is authenticated
echo ("Welcome User: " . $data["user_id"]);
// And now you have the Graph API auth token in $data["oauth_token"],
// so you can use any graph api method
FYI : iFrames에서 제 3 자 쿠키를 수락 할 수없는 추가 보안 기능이 있습니다.이 경우 iFrame에 의해 거부되는 Facebook의 승인 쿠키가 될 것입니다. IE 브라우저가 서비스를 제공 할 수 없음을 의미합니다. 귀하의 iFrame 응용 프로그램 ....). 이 문제를 해결하려면 HTTP 응답에 P3P 헤더를 추가해야합니다. – Amir