如何将用户重定向到认证对话框



我遵循这里的步骤

我的应用程序不会重定向用户

$app_id = APP_ID;
$canvas_page = APP_LINK;
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=". $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,read_stream";
echo "<script> top.location.href='" . $auth_url . "'</script>";

PS:我成功地用<fb:redirect>重定向了用户,但由于FBML在几个月内将不受支持,我想找到另一种方法和"top.location"。

您可能需要一个分号来执行代码。同样,等号也是必要的。(感谢David Barker)

$app_id = APP_ID;
$canvas_page = APP_LINK;
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=". $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,read_stream";
echo "<script> top.location.href='" . $auth_url . "';</script>";

当你这样做的时候,你得到了什么:echo "<script> alert('".$auth_url."');</script>"; ?

同样,在PHP中更简单的方法是:

$app_id = APP_ID;
$canvas_page = APP_LINK;
$auth_url = "http://www.facebook.com/dialog/oauth?client_id". $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=email,read_stream";
echo <<<EOT
  <script>
    top.location.href="$auth_url";
    //checking the value of auth_url to see if that is the reason redirect is not happening.
    if (window.console) { 
        console.log("$auth_url"); 
      } else { 
        alert("$auth_url"); 
      }
  </script>
EOT;

使用heredoc语法你不需要转义任何东西,你可以在里面使用单引号和双引号,并且变量在你的字符串中被本质上替换。div;)

最新更新