Facebook iframe application after authorization redirect to facebook page tab

安稳与你 提交于 2019-12-24 02:13:22

问题


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

回答1:


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>


来源:https://stackoverflow.com/questions/4143045/facebook-iframe-application-after-authorization-redirect-to-facebook-page-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!