Question

I am creating a facebook application with PHP and facing two main problems..

  1. When I click allow on the permission, the app takes me to my own domain (where application is stored) instead of loading it in an iFrame.

  2. Sometimes when I click "Don't allow", it still lets me in and shows a PHP error, while sometimes (most of the times), it doesn't let me in.

What could be the problem? Any way I can programatically redirect to the permissions page? Thank you..

if(empty ($this->session))
    {
        try
        {
            $login_url = $this->facebook->getLoginUrl();
            header("Location: ".$login_url);
        }
        catch(Exception $e)
        {
            header("Location: http://www.facebook.com");
        }
    }
    else
    {
        try
        {
            $this->uid = $this->facebook->getUser();
        }
        catch(Exception $e)
        {
            header("Location: http://www.facebook.com");
        }
    }

note the redirects I made were to try to solve the problem. But no exception is thrown.

Was it helpful?

Solution 2

I used this simple script to apply redirect if the page is not inside iFrame...

if(parent == window)
                {
                    window.location = "http://apps.facebook.com/appname/";
                }

This might not be a legal solution, but solved the situation for me. Anybody if knows the legal way, please post. Thanks.

OTHER TIPS

When you want to get the login url you can pass different params based on what you need. in your case, to go back to facebook page url you can use the next param.

This is your code modified:

$login_url = $this->facebook->getLoginUrl(
            array(
                'canvas'    => 1,
                'fbconnect' => 0,
                'next' => YOUR_CANVAS_PAGE_URL
            ) 
        );
if(empty ($this->session))
{
    echo "<script type='text/javascript'>top.location.href='$loginUrl';</script>";
    exit;
}
else
{
    try
    {
        $this->uid = $this->facebook->getUser();
    }
    catch(Exception $e)
    {
        echo "<script type='text/javascript'>top.location.href='$loginUrl';</script>";
        exit;
    }
}

Let me know if it solves your problem :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top