简体   繁体   中英

How to implement cancel action on facebook page tab app

I am working on a facebook app which is implement with php api . The problem that I face is that when I click cancel it redirects me on the same button which means that I cannot close the dialog at all . I want to find a way when user clicks cancel button to redirect him on fb page of the app. Is there any way that I can catch with php the cancel action . I am stuck with this many hours .. I am providing some code below :

if(!$user){
  $loginUrl = '';

  if(isset($signed_request["app_data"])){

    $loginUrl = $this->fb->getLoginUrl(
      array(
          'canvas' => 1,
          'scope' =>'email, user_likes',
          'redirect_uri'=>$curContest->fbpagelink .'?sk=app_'.$curContest->app_id . '?app_data=' . $signed_request["app_data"]
      )
    );
  }else {
    $loginUrl = $this->fb->getLoginUrl(
      array(
          'canvas' => 1,
          'scope' =>'email, user_likes',
          'redirect_uri'=>$curContest->fbpagelink .'?sk=app_'.$curContest->app_id
      )
    );
  }
  /* Redirect the main window NOT the iframe */
  //print_r($_GET['app_data']);
    echo '<script>top.location="'.$loginUrl.'";</script>';
}else{
//code of the app when user click on okay button ...
} 

When user cancels the authorization option, the facebook redirects him back to your application with a 'error' parameter in return url..

so in code you can write

if($_GET('error') || $_GET('error_reason')){
   // redirect to your facebook page

}

Hope this works for you !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM