0
나는 사용자가 자신의 FB 계정을 통해 인증 할 수 있음을 원하고, 내가 그들의 데모 스크립트 시도 :페이스 북 데모 스크립트 문제
$app_id = "*****";
$app_secret = "*****";
$my_url = "http://localhost/fb/fb.php";
session_start();
$code = $_REQUEST["code"];
if(empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'];
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
if($_REQUEST['state'] == $_SESSION['state']) {
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;
$response = @file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$graph_url = "https://graph.facebook.com/me?access_token="
. $params['access_token'];
$user = json_decode(file_get_contents($graph_url));
echo("Hello " . $user->name);
echo "$user->name";
}
else {
echo("The state does not match. You may be a victim of CSRF.");
}
문제는 그런 성공적인 로그인 후 단지 "안녕하세요" 문자열이 표시되지만 $ user-> name은 표시되지 않습니다.
dialog_url을 https : //로 변경하려고 시도하십시오. oauth2.0은 https (oauth2 사양에 따라)를 통해서만 작동해야합니다. – Rufinus