Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook: force user to login / install application with FBML

Tags:

I am new to Facebooks applications, so forgive me if I got something wrong.

How do I prompt users to install my application when they visit my application's canvas page?

like image 743
flybywire Avatar asked Feb 07 '10 18:02

flybywire


1 Answers

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

like image 138
Sarfraz Avatar answered Oct 12 '22 23:10

Sarfraz