Я следую этому уроку. http://developers.facebook.com/docs/authentication/
но он перенаправляет два раза. сначала с code = NULL, и в следующий раз он будет иметь код. Я не хочу перенаправлять, когда code = NULL .plz подскажет решение Вот мой полный код.
$code = $_REQUEST['code']; if(empty($code)) { $dialog_url="https://www.facebook.com/dialog/oauth?client_id=$app_id&redirect_uri=$my_url&scope=email"; echo("<script> top.location.href='" . $dialog_url . "'</script>"); } $token_url = "https://graph.facebook.com/oauth/access_token?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret=" . $app_secret . "&code=" . $code; $access_token = file_get_contents($token_url); $graph_url = "https://graph.facebook.com/me?" . $access_token; $user = json_decode(file_get_contents($graph_url));
include_once 'config.php'; include_once 'lib.php'; $code = $_REQUEST["code"]; if(empty($code)) { $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state" . $_SESSION['state']."&scope=email,user_birthday"; $request_ids = $_REQUEST['request_ids'];//"&request_ids=".$request_ids if(isset($_REQUEST['request_ids'])) { $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url."?request_ids=".$request_ids) . "&state" . $_SESSION['state']."&scope=email,user_birthday"; } echo("<script> top.location.href='" . $dialog_url . "'</script>"); } else { if(isset($_REQUEST['request_ids'])) { $theUrl = "http://apps.facebook.com/animathegame/index.php?request_ids=".$_REQUEST['request_ids']; } else { $theUrl = "http://apps.facebook.com/animathegame/index.php"; } $urls = "https://graph.facebook.com/oauth/access_token?client_id=".$app_id."&redirect_uri=".$theUrl."&client_secret=".$app_secret."&code=".$code; $token = file_get_contents($urls); $sessionId = $token; $urlss = "https://graph.facebook.com/me?".$token; $thoken = file_get_contents($urlss); $access_token_array = json_decode($thoken, true); $userId = $access_token_array['id']; $email = $access_token_array['email']; $fullname = $access_token_array['name']; $fname = $access_token_array['first_name']; $lname = $access_token_array['last_name'];