0

My facebook app is getting redirected out of the iFrame on authorization. I have used the facebook.php and base_facebook.php from gitHub without any change and have pretty much followed example.php. What could I be missing?:

$facebook = new Facebook(array(
    'appId'  => $configParam['appId'],
    'secret' => $configParam['secret']
));
$appId=$configParam['appId'];
$user = $facebook->getUser();
if ($user==null) {
    $loginUrl = $facebook->getLoginUrl(array(
            'scope' => $perm
                ));     
    $loginUrl = $facebook->getLoginUrl();
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}

The loginUrl is constructed in base_facebook.php as:

$this->establishCSRFTokenState();
$currentUrl = $this->getCurrentUrl();
return $this->getUrl(
'www',
'dialog/oauth',
array_merge(array(
        'client_id' => $this->getAppId(),
        'redirect_uri' => $currentUrl, // possibly overwritten
        'state' => $this->state),
      $params));
6
  • So, the redirect_uri is the current URL (www.myserver.com/myapp/index.php). If I hardcode redirect_uri as apps.facebook.com/myapp, facebook throws an error ("redirect_uri isn't an absolute URI"). Usually people run into this problem if any of their basic app settings are flawed, but I don't see anything wrong. Here are my basic settings: siteurl: myserver.com/myapp namespace: <app name> //so I do have namespace set canvasUrl: myserver.com/myapp secure canvas url: myserver.com/myapp Commented Oct 28, 2012 at 7:35
  • possible duplicate of After Facebook installa facebook app redirects me to the url but outside of Facebook
    – ifaour
    Commented Oct 28, 2012 at 11:53
  • p.s: make sure to add the https protocol to your canvas url hence: https://apps.facebook.com/app_namespace/
    – ifaour
    Commented Oct 28, 2012 at 12:35
  • when I give a redirect_uri (instead of of current url), I get the error: API Error Code: 191 API Error Description: The specified URL is not owned by the application Error Message: redirect_uri isn't an absolute URI. Check RFC 3986. I get this error irrespective of giving myserver.com/myapp or apps.facebook.com/namespace I am using https Commented Oct 28, 2012 at 17:02
  • The above problem goes away when I change my canvas url to https. But now the application loops infinitely Commented Oct 28, 2012 at 17:14

1 Answer 1

0

It is a combination of things you have take care of to solve these two problems: 1. facebook authorization redirecting app out of iFrame (as mentioned by ifaour) 2. app going into a loop 3. app going into a loop only in IE

For (1), everything must be consistently https (or http). I did have my secure canvas url as https but had left my canvas url as http (I thought this was fine). Apparently, both should be https

For (2), the OOB facebook-php integration code at GitHub uses Current URL as redirect_uri. You have to change that to apps.facebook.com/namespace- note that that this has to be done at two places in base_facebook.php - getLoginUrl and getAccessTokenFromCode

For (3) look at Why my FB app loops forever in IE?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.