2
votes

My app is inside a fan page, when i request permission it will show the dialog. The problem is after user accept, they are redirected to real app page (url here app is hosted)

for understand better i have the url generated with facebook PHP SDK

https://www.facebook.com/dialog/oauth?client_id=341572315885516&redirect_uri=https%3A%2F%2Fmywebapp.com%2Fyii%2Folivi%2Ffacebook%2Fapp%2Fid%2F1%2F&state=40e532d364f67631cfc1ef6061609157&canvas=1&fbconnect=0&scope=user_about_me%2Cuser_birthday

As we can see will redirect outside of facebook, i want redirect back in that case: https://www.facebook.com/mypage/app_341572315885516

Any way to solve this situation? I have tried a lot of things nothing works...

Wheres my code:

<?php $userid = Yii::app()->facebook->getUser(); ?>
<?php $results = NULL;//$results = Yii::app()->facebook->api('/me'); ?>

<?php 

    $signed_request = Yii::app()->facebook->getSignedRequest();
    if(!isset($signed_request['page']) || !isset($signed_request['page']['liked']))
    {
        $this->renderPartial('_nofan', array('model'=>$model));
    }
    else
    {
        if(!$signed_request['page']['liked'])
        {
            $this->renderPartial('_nofan', array('model'=>$model));
        }
        else
        {
            try
            {
                $results = Yii::app()->facebook->api('/me');
            }
            catch (FacebookApiException $e) {

            }
            if(!$userid || !$results) 
            {
                $loginUrl = Yii::app()->facebook->getLoginUrl(array('scope'=>'user_about_me,user_birthday'));
                /*echo "<script type='text/javascript'>top.location.href = '{$loginUrl}';</script>";*/
                Yii::app()->clientScript->registerScript('login-perm', 'top.location.href = "'.$loginUrl.'";', CClientScript::POS_HEAD);
                //$this->redirect($loginUrl);
                /*Yii::app()->facebook->addJsCallback("FB.login(function(response) {
                                                  if (response.authResponse) {
                                                      // user is logged in and granted some permissions.
                                                  } else {
                                                    // User cancelled login or did not fully authorize.
                                                  }
                                                }, {scope:'user_about_me,user_birthday'});");*/
            }

            // FAN

            //echo 'Olá';
        }
    }

?>

Thanks

1

1 Answers

0
votes

You can try redirect_uri paramaeter,

Ex:

$redirecturl = https://www.facebook.com/mypageonfacebook/app_APPID;

$params = array('scope' => 'email, publish_actions', 'redirect_uri' => $redirecturl);

$loginUrl = $facebook->getLoginUrl($params);       

echo("<script> top.location.href='".$loginUrl."'</script>");

hope this will help you.. thanks..