简体   繁体   English

Facebook重定向到画布网址,而不是Facebook上的应用程序

[英]Facebook redirects to canvas url instead of the app on facebook

I wrote a facebook app that works as a tab on a page. 我写了一个Facebook应用程序,作为页面上的选项卡。

Here is my config.php file which contains the configuration and redirects to the authentication page if the user has not yet approved the app: 这是我的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>";
}
?>

Here is my main file: 这是我的主要文件:

    <?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>

As I mentioned before, this app works as a tab on a facebook page and not as a stand-along facebook app, therefore there is no canvas url. 正如我之前提到的,这个应用程序作为Facebook页面上的选项卡而不是作为一个独立的Facebook应用程序,因此没有画布网址。 The page tab url is: http://www.gate7.co.il/fbapps/predictor/ . 页面标签页为: http//www.gate7.co.il/fbapps/predictor/

When a user enters the tab, he gets redirected to the authentication page (from the config.php), but when the authentication process is done, the user gets redirected to the page tab url (http://www.gate7.co.il/fbapps/predictor/) instead of the tab inside the page. 当用户进入选项卡时,他会被重定向到身份验证页面(来自config.php),但是当身份验证过程完成后,用户将被重定向到页面选项卡URL(http://www.gate7.co。 il / fbapps / predictor /)而不是页面内的选项卡。

I tried to add these lines to the index file: 我试图将这些行添加到索引文件中:

        <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>

It worked well on firefox, and the user got redirected from the page tab url to the actual tab in the page, but in chrome it just caused mess and showed facebook inside the tab. 它在firefox上运行良好,并且用户从页面选项卡url重定向到页面中的实际选项卡,但在chrome中它只是导致混乱并在选项卡内显示facebook。

What's the solution for this? 这是什么解决方案?

In your getLoginUrl() call, set the redirect_uri param to your tab page, like this: 在你的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'
));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM