Question

I have a php web app set up to handle my new facebook application. I am looking at my app at http://apps.facebook.com/myapp and it shows my app in an iframe.

I am trying to get the app to bring up the screen where it requests permission. I can't seem to find a anything that explains the flow. I don't have an issue reading profile details once I create the $fb->loginUrl() link and click through to it, but I want a permission request to load automatically when you go first to the app.

Was it helpful?

Solution

Try this code - It is working code that I use when I create application. I assume from your message that you use PHP SDK

< ?php
    require_once('facebook.php');
// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => 'YOUR APP ID',
  'secret' => 'YOUR APP SECRET',
  'cookie' => true
));
if ($user = $facebook->getUser()) { //user is logged in and authorized us
    $user = $facebook->getUser();
    $fbme = $facebook->api('/me');
    print "Welcome User ID: " . $user;
    print_r($fbme);

} else { // User has not authorized us or is not logged in
    $params = array(
        'fbconnect'=>0,
                'canvas'=>1,
        'req_perms'=>'publish_stream,email',
    // For a full list of permissions: http://developers.facebook.com/docs/authentication/permissions
    );
    $loginUrl = $facebook->getLoginUrl($params);
     print "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}

Don't forget to test it on new and fresh browser and other account.

OTHER TIPS

with new php sdk getSessions() isn't working anymore, should use it like this `:

if ($user = $facebook->getUser()) { //user is logged in and authorized us

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