views:

545

answers:

2

I am a facebooks apps newbie, so forget me if I got something wrong.

I want to prompt users to install my app when they visit my app's canvas page.

any help?

+5  A: 

You need to put below code on top of the first access page to your application:

$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
$user = $facebook->require_login();

//catch the exception that gets thrown if the cookie has an invalid session_key in it
try
{
    if (!$facebook->api_client->users_isAppUser())
    {
        $facebook->redirect($facebook->get_add_url());
    }
}
catch (exception $ex)
{
    //this will clear cookies for your application and redirect them to a login prompt
    $facebook->set_user(null, null);
    $facebook->redirect($iframepath);
}

Put in the your own API key and secret key. Thanks

Sarfraz
Yep, that's how it's done. `$facebook->require_frame();` can be removed, however.
LiraNuna
@LiraNuna: Thanks for adding that useful info :)
Sarfraz
A: 

Well, there are several ways to do it depending on if you are using the iframe or fbml canvas. Check this link: http://wiki.developers.facebook.com/index.php/Authorization_and_Authentication_for_Canvas_Page_Applications_on_Facebook

felix

related questions