facebookfbml

Error message when trying to request permissions after user denies request (using Facebook PHP SDK)


I'm using the PHP Facebook SDK (v.3.1.1) for building my Facebook app. At some point in my flow I need the user to accept my app. I'm using the following code:

// Is there an error? Redirect to explain permissions page
if(!empty($_GET['error'])) {
    $redirectUrl = APP_FACEBOOK_PAGE;
require_once(ABSOLUTE_DOCUMENTROOT_PATH.'do_redirect.inc.php');
die();  
}

// Prepare app
$facebook = new Facebook(array(
    'appId'  => APP_ID,
    'secret' => APP_SECRET,
    'cookie'=> true
));
$facebookId = $facebook->getUser();

// Changed user?
if((!empty($_SESSION['facebookAuth']['facebookId']) && $_SESSION['facebookAuth']    ['facebookId'] != $facebookId)) {
    $facebook->setAccessToken('');
    $_SESSION['facebookAuth']['facebookId'] = $facebookId;
    $redirectUrl = getRequestPermissionsUrl($facebook);
    require_once(ABSOLUTE_DOCUMENTROOT_PATH.'do_redirect.inc.php');
    die();
}

// No access token? Re-acquire it!
if($facebook->getAccessToken() == '') {
    $redirectUrl = getRequestPermissionsUrl($facebook);
    require_once(ABSOLUTE_DOCUMENTROOT_PATH.'do_redirect.inc.php');
    die();
}

// Let's see if we have an active session
if(!empty($_SESSION['facebookAuth']['facebookId']) && !empty($_SESSION['facebookAuth']    ['facebookUserObject'])){
    $facebookId = $_SESSION['facebookAuth']['facebookId'];
    $facebookUserObject = $_SESSION['facebookAuth']['facebookUserObject'];
}else{
    $facebookId = $facebook->getUser();

    if ($facebookId) {
        try {
            $facebookUserObject = $facebook->api('/me');
            // Put them in session so we can re-use them
            $_SESSION['facebookAuth']['facebookId'] = $facebookId;
            $_SESSION['facebookAuth']['facebookUserObject'] =     $facebookUserObject;
        } catch (FacebookApiException $e) {
            error_log($e);
        }
    }
}

// If no facebookId -> check permissions anyway
if(empty($facebookId)) {
    $redirectUrl = getRequestPermissionsUrl($facebook);
    require_once(ABSOLUTE_DOCUMENTROOT_PATH.'do_redirect.inc.php');
    die();
}

My function 'getRequestPermissionsUrl' calls for the getLoginUrl:

return $redirectUrl = $facebookObject->getLoginUrl(array('canvas'=>1,'fbconnect'=>0,'redirect_uri'=>$returnUrl,'scope'=>'publish_stream,email,user_likes'));

the file 'do_redirect.inc.php' does a js-redirect:

top.location.href = '$redirectUrl';

So, with that in mind let's take a look at the first part. This code gets included again after the user has denied the permission and the page reloads. In that case $_GET['error'] is filled and we'll be redirected to another php-file in the app - a file that does not include the code I posted but has nothing to do with permissions or stuff at all. In that other file is a link to the page that needs permission again - the code above gets loaded again but when trying to request permissions I'm getting the error 'something went wrong and we're trying to fix it' on a Facebook page.

I've tried evertyhing from destroying sessions to setting the accestoken empty to... you name it. I'm quite out of ideas now so I'd be glad if somebody of you guys have any suggestions. Any help would be greatly appreciated.

Thanks in advance!


Solution

  • I just saw a newer question asking the same thing - Sorry, something went wrong after cancel application connexion on SDK 3.0

    There is a currently open bug in Facebook's bug tracker about this