facebook重定向uri重定向到本地域,而不是停留在facebook上


facebook redirect_uri redirecting to local domain instead of staying on facebook

显示请求权限对话框后,我的facebook应用程序将不会停留在facebook上。它一直重定向到redirect_uri(显而易见),但我的问题是如何让应用程序在facebookiframe中运行?

我已尝试将redirect_uri设置为https://apps.facebook.com/myApp但这是不允许的,它显示了一个错误?

应用程序配置不允许给定的URL。:应用程序的设置不允许使用一个或多个给定的URL。它必须与网站URL或Canvas URL匹配,或者域必须是应用程序某个域的子域。

我当前的代码

<?php
require 'facebook/facebook.php';
// Get User ID
$facebook_config = array(
  'appId'  => '8**************3',
  'secret' => '5*************************d',
  'cookie'  =>  true
);
$facebook = new Facebook($facebook_config);
$user = $facebook->getUser();
$login_url = $facebook->getLoginUrl(array(
  'redirect_uri' => 'localhost';
  'scope'   =>  'user_location'
));
$logout_url = $facebook->getLogoutUrl();
if($user)
{
    $user_profile = $facebook->api('/me');
    header("Content-Type:text/plain");
    print_R($user_profile);
    die();
}
else if(!$user)
{
    echo "<script type='text/javascript'>top.location.href = '$login_url';</script>";
}
?>

您可以删除此行:'redirect_uri' => 'localhost';

因为,登录后,如果redirect_uri中没有提到任何内容,它将自动重定向到同一页面。

如果你想转到其他页面,比如success.php,你应该给redirect_uri wrt画布url,即这个页面的实际url,而不是http://apps.facebook.......

感谢您的回答,但删除'redirect_uri' => 'localhost';后,它仍然重定向到localhost并被卡住。

我做了一个快速修复,重定向回facebook

$token = $_GET['code'];
if ($token) { ?>
<form action="https://apps.facebook.com/MyApp/" method="post" name='frm'>
    <input type="hidden" name="token" value="<?=$token?>">
</form>
<script language="JavaScript">
    document.frm.submit();
</script>

这将所有内容重定向回facebook,并且会起作用,但正如你在这里所说的

如果你想转到其他页面,比如success.php,你应该给redirect_uri wrt画布url,即这个页面的实际url,而不是http://apps.facebook.......

我把redirect_uri从localhost改为https://apps.facebook.com/MyApp/index.php,一切都很顺利,