iFrame app.在用户授权应用后重定向回页面标签



我有很多麻烦让我的facebook应用程序重定向回到一个页面上的标签一旦用户授权它。

我的应用程序将生活在多个页面,所以它不像在重定向中粘贴url那么容易。是否有一种方法来抓取页面的id并将其放入重定向url?这是我的代码…

<?php  
session_start();
 //facebook application configuration -mahmud
$fbconfig['appid' ] = "xxx";
$fbconfig['secret'] = "xxxxxxxxxxxxx";
$fbconfig['baseUrl']    =   "http://localhost/foods/";
$fbconfig['appBaseUrl'] =   ""; //Need page tab url here

/* 
 * If user first time authenticated the application facebook
 * redirects user to baseUrl, so I checked if any code passed
 * then redirect him to the application url 
 * -mahmud
 */
if (isset($_GET['code'])){
    //header("Location: " . $fbconfig['appBaseUrl']);
   // exit;
}
//~~
//
if (isset($_GET['request_ids'])){
    //user comes from invitation
    //track them if you need
}
$user            =   null; //facebook user uid
try{
    include_once "facebook.php";
}
catch(Exception $o){
    echo '<pre>';
    print_r($o);
    echo '</pre>';
}
// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => $fbconfig['appid'],
  'secret' => $fbconfig['secret'],
  'cookie' => true,
));
//Facebook Authentication part
$user       = $facebook->getUser();
// We may or may not have this data based 
// on whether the user is logged in.
// If we have a $user id here, it means we know 
// the user is logged into
// Facebook, but we don’t know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
$loginUrl   = $facebook->getLoginUrl();
if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    //you should use error_log($e); instead of printing the info on browser
    d($e);  // d is a debug function defined at the end of this file
    $user = null;
  }
}
if (!$user) {
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
    exit;
}
//get user basic description
$userInfo           = $facebook->api("/$user");
function d($d){
    echo '<pre>';
    print_r($d);
    echo '</pre>';
}

$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request['page']['id'];

$_SESSION['pageID']=$page_id; 
$_SESSION['userID'] = $user;

 ?>

试着注释这一行:"top.location回响。href = '$loginUrl';";

我相信在标签页上登录的默认行为是保持在该标签页上。你不需要告诉它去那里

最新更新