facebook图形API连接

facebook图形API连接,facebook,facebook-graph-api,Facebook,Facebook Graph Api,我正在学习那个教程 但它重定向了两次。首先使用code=NULL,然后下一次使用该代码。。当code=NULL时,我不想重定向。请告诉我解决方案。这是我的完整代码 $code = $_REQUEST['code']; if(empty($code)) { $dialog_url="https://www.facebook.com/dialog/oauth?client_id=$app_id&redirect_uri=$my_url&scope=email"; e

我正在学习那个教程

但它重定向了两次。首先使用code=NULL,然后下一次使用该代码。。当code=NULL时,我不想重定向。请告诉我解决方案。这是我的完整代码

$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));
$code=$\u请求['code'];
if(空($code)){
$dialog_url=”https://www.facebook.com/dialog/oauth?client_id=$app\u id&redirect\u uri=$my\u url&scope=email”;
echo(“top.location.href=”。$dialog\u url。””;
}
$token_url=”https://graph.facebook.com/oauth/access_token?client_id="
. $应用程序id。“&重定向_uri=”。urlencode($my_url)。“&client\u secret=”
. $你的秘密。“&code=”$密码
$access\u token=file\u get\u contents($token\u url);
$graph_url=”https://graph.facebook.com/me?" . $接入令牌;
$user=json_decode(文件获取内容($graph_url));
包括一次'config.php';
包括_once'lib.php';
$code=$_请求[“code”];
if(空($code))
{
$dialog_url=”http://www.facebook.com/dialog/oauth?client_id=" 
.$app_id.&redirect_uri=“.urlencode($my_url)。”&state“
.$\会话['state']。“&scope=电子邮件,用户\生日”;
$request\u ids=$\u request['request\u ids'];/“&request\u ids=“.$request\u ids
如果(isset($\u请求['REQUEST\u id']))
{
$dialog_url=”http://www.facebook.com/dialog/oauth?client_id=" 
.$app_id.&redirect_uri=“.urlencode($my_url.?request_id=“.$request_id)。”&state“
.$\会话['state']。“&scope=电子邮件,用户\生日”;
}
echo(“top.location.href=”。$dialog\u url。””;
}
其他的
{
如果(isset($\u请求['REQUEST\u id']))
{
$theUrl=”http://apps.facebook.com/animathegame/index.php?request_ids=“$_请求['REQUEST_id'”;
}
其他的
{
$theUrl=”http://apps.facebook.com/animathegame/index.php";
}
$URL=”https://graph.facebook.com/oauth/access_token?client_id=“$app_id.”和redirect_uri=“.$theUrl.”和client_secret=“.$app_secret.”和code=“.$code;
$token=文件内容($URL);
$sessionId=$token;
$urlss=”https://graph.facebook.com/me?“$token;
$thoken=文件获取内容($urlss);
$access\u token\u array=json\u decode($thoken,true);
$userId=$access\u token\u array['id'];
$email=$access_token_array['email'];
$fullname=$access\u token\u array['name'];
$fname=$access_token_array['first_name'];
$lname=$access\u token\u数组['last\u name'];

为什么它会重定向您两次?您的
$my\u 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'];