Facebook重定向到canvas url,而不是Facebook上的应用程序


Facebook redirects to canvas url instead of the app on facebook

我写了一个facebook应用程序,它可以作为页面上的标签。

这是我的config.php文件,其中包含配置和重定向到认证页面,如果用户尚未批准应用程序:

<?php
require_once("database.php");
require_once("functions.php");
require_once("facebook.php");
$config = array
(
    'database' => array
    (
        'host' => 'localhost',
        'name' => '***',
        'username' => '***',
        'password' => '***'
    )
);
$db = new Database($config['database']['host'], $config['database']['name'], $config['database']['username'], $config['database']['password']);
$db->connect();
$facebook = new Facebook(array(
    'appId' => '***',
    'secret' => '***',
    'cookie' => true
));
$user = $facebook->getUser();
if ($user)
{
    try
    {
        $me = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}
if ($user)
    $logoutUrl = $facebook->getLogoutUrl();
else
{
    $loginUrl = $facebook->getLoginUrl(array(
        'scope' => 'email,user_about_me,user_likes,user_status,read_stream,offline_access,publish_stream,publish_actions'
    ));
}
if (!$user)
{
    echo "<script type='"text/javascript'">top.location.href = '".$loginUrl."';</script>";
}
?>

这是我的主文件:

    <?php
    require_once("includes/config.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="he" lang="he" dir="rtl">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=windows-1255" />
        <title>
            שער 7 - הלב הצהוב | מכבי תל אביב
        </title>
    </head>
    <body>
        <?php
            $clLike = $facebook->api('/me/likes/204623816223540');
            if (!empty($clLike['data']))
                echo "I'm a fan!";
            else
                echo "I'm not a fan :(";
        ?>
    </body>
</html>

正如我之前提到的,这个应用程序在facebook页面上作为一个标签,而不是作为一个独立的facebook应用程序,因此没有画布url。页面标签url为:http://www.gate7.co.il/fbapps/predictor/.

当用户进入选项卡时,他被重定向到身份验证页面(来自config.php),但是当身份验证过程完成时,用户被重定向到页面选项卡url (http://www.gate7.co.il/fbapps/predictor/),而不是页面内的选项卡。

我尝试将这些行添加到索引文件中:

        <script type="text/javascript">
        if (top.location.href != "http://www.facebook.com/gate7yellowheart?sk=app_196175180456372")
            window.location = "http://www.facebook.com/gate7yellowheart?sk=app_196175180456372";
    </script>

它在firefox上工作得很好,用户从页面标签url重定向到页面中的实际标签,但在chrome中,它只是造成混乱,并在标签中显示facebook。

这个问题的解决方案是什么?

在getLoginUrl()调用中,为选项卡页面设置redirect_uri参数,如下所示:

$loginUrl = $facebook->getLoginUrl(array(
    'scope' => 'email,user_about_me,user_likes,user_status,read_stream,offline_access,publish_stream,publish_actions',
    'redirect_uri' => 'http://www.facebook.com/gate7yellowheart?sk=app_196175180456372'
));