Facebook 图形 API 连接

发布于 2024-11-04 03:08:28 字数 862 浏览 0 评论 0原文

我正在遵循该教程。 http://developers.facebook.com/docs/authentication/

但它重定向两次。首先使用 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));

i am following that tutorial. http://developers.facebook.com/docs/authentication/

but it redirect two times. first with code=NULL and the next time it will have the code.. i dont want to redirect when code = NULL .plz tell me the solution. Here is my complete code.

$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));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗心人 2024-11-11 03:08:28
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'];
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'];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文