Facebook iframe 应用程序授权后重定向到 Facebook 页面选项卡

发布于 2024-10-01 22:24:31 字数 1204 浏览 6 评论 0原文

我在授权后将用户重定向回 Facebook 页面中的应用程序选项卡时遇到问题。我总是最终进入独立的应用程序画布页面。

编辑: 它本来是一个选项卡中的应用程序 在 Facebook 页面内。我想做 授权然后重定向 用户返回页面选项卡。但当你这样做时 这个选项卡看起来就像以前一样 对用户来说似乎是一个错误 因为他来自授权并且 选项卡中的应用程序看起来相同。他有 单击它以获得某种 回复或消息。

是否有任何可以下载的示例或某种分步教程。这是我的代码:

// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => $fbconfig['appid'],
  'secret' => $fbconfig['secret'],
  'cookie' => true,
));

//Facebook Authentication part
$session = $facebook->getSession();
$loginUrl = $facebook->getLoginUrl(
        array(
        'canvas'    => 1,
        'fbconnect' => 0,
        )
);

$uid = null; //facebook user id
$fbme = null;

if (!$session) {
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
    exit;
}
else {
    try {
        $uid  = $facebook->getUser();
        $fbme = $facebook->api('/me?fields[]=id&fields[]=last_name&fields[]=first_name');
    }
    catch (FacebookApiException $e) {
        echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
        exit;
    }
}

I have problems with redirecting user after authorization back to the app tab in facebook page. I always end up in standalone application canvas page.

Edit:
It was meant to be an app in tab
within a Fb page. I wanted to do the
authorization and then to redirect
user back to page tab. But when you do
this the tab looks just like before
and it seems to user like an error
because he came from authorization and
the app in tab looks the same. He has
to click on it to get some kind of
response or message.

Is there any example that can be downloaded or some kind of step-by-step tutorial. Here is my code:

// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => $fbconfig['appid'],
  'secret' => $fbconfig['secret'],
  'cookie' => true,
));

//Facebook Authentication part
$session = $facebook->getSession();
$loginUrl = $facebook->getLoginUrl(
        array(
        'canvas'    => 1,
        'fbconnect' => 0,
        )
);

$uid = null; //facebook user id
$fbme = null;

if (!$session) {
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
    exit;
}
else {
    try {
        $uid  = $facebook->getUser();
        $fbme = $facebook->api('/me?fields[]=id&fields[]=last_name&fields[]=first_name');
    }
    catch (FacebookApiException $e) {
        echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
        exit;
    }
}

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

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

发布评论

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

评论(1

旧伤慢歌 2024-10-08 22:24:31

没关系,我已经在“页面”选项卡中使用 Ajax 完成了授权。此方法也在问题“Facebook 粉丝页面选项卡和用户”中进行了描述id。”:

<div id="intro">
    <a onclick="load_iframe();"><img src="<?php echo $fbconfig['baseUrl'], 'intro.jpg' ?>" /></a>
</div>
<div id="fb-root"></div>

<script type="text/javascript" charset="utf-8">

    function load_iframe()
    {
        var intro = document.getElementById('intro');
        var root = document.getElementById('fb-root');

        var ajax = new Ajax();
        ajax.responseType = Ajax.FBML;
        ajax.onerror = function(error)
        {
            new Dialog().showMessage("Alert", "Required authorization.","Close");
        };

        ajax.ondone = function(data)
        {
            intro.setStyle('display', 'none');
            root.setInnerFBML(data);
        }
        ajax.requireLogin = true;
        ajax.post("<?php echo $fbconfig['baseUrl'] ?>iframe.php");
    }
</script>

Never mind I've done authorization using Ajax within Page tab. This method is also described in question "Facebook fan page tab and user id.":

<div id="intro">
    <a onclick="load_iframe();"><img src="<?php echo $fbconfig['baseUrl'], 'intro.jpg' ?>" /></a>
</div>
<div id="fb-root"></div>

<script type="text/javascript" charset="utf-8">

    function load_iframe()
    {
        var intro = document.getElementById('intro');
        var root = document.getElementById('fb-root');

        var ajax = new Ajax();
        ajax.responseType = Ajax.FBML;
        ajax.onerror = function(error)
        {
            new Dialog().showMessage("Alert", "Required authorization.","Close");
        };

        ajax.ondone = function(data)
        {
            intro.setStyle('display', 'none');
            root.setInnerFBML(data);
        }
        ajax.requireLogin = true;
        ajax.post("<?php echo $fbconfig['baseUrl'] ?>iframe.php");
    }
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文