0
나는이 페이스 북의 로그인 코드테스트 방법 페이스 북에 접속하지 않은 상태에서 로그인 했습니까?
$app_id = "xxxxxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$my_url = "http://xxxxxxxxxxxxx";
$code = $_REQUEST["code"];
if(empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "https://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>");
print_r($dialog_url);
die();
}
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 ."<a href=event.php?app_id=".$app_id."&app_secret=".$app_secret."&code=".$code."&access_token=".$response."> Create Event</a>");
}
else {
echo("The state does not match. You may be a victim of CSRF.");
}
내가 이미 페이스 북의 웹 사이트에 연결하고있는 경우,이 페이지에 로그인 고려 테스트 할 수 있나요? 로그인 링크가 표시되지 않습니까?
질문에 대답하지 않습니다. 사용자가 이미 연결되어있는 경우 로그인 링크가 표시되지 않도록 앱에서 사용자의 로그인 상태를 확인하는 방법을 알고 싶어했습니다. – CBroe