开发者

Facebook iframe application after authorization redirect to facebook page tab

I have problems with redirecting user开发者_JS百科 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;
    }
}


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜