2011-11-16 51 views
0

我有很多麻煩讓我的Facebook應用程序在用戶授權後重定向回頁面選項卡。iFrame應用程序..在用戶授權應用程序後重定向回頁面選項卡

我的應用程序將生活在多個頁面上,因此它不像爲重定向粘貼網址那麼簡單。有沒有辦法抓取網頁的ID並將其放入重定向網址?這裏是我的代碼...

<?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; 


?> 

回答

0

嘗試註釋掉這一行: 回聲 「top.location.href = '$ loginUrl';」;

我相信在標籤頁上登錄的默認行爲是保留在該標籤頁上。你不必告訴它去那裏。

+0

我評論說,但我的應用程序現在不加載。 – Dustin

+0

每當我刪除所有提到這件事把我送到我的應用程序的網頁的重定向,有幾個查詢字符串 的http://本地主機/食品/狀態= 05efbcc4c5bf591e56f518ee16a375ce&代碼= AQCAlYQpbJmCttiE7nDCxCVOWB6gAg51hpb4LTj2g5zmvylE6_p0sJ8BDRoHH7Z1jwncnUwJGbl-2E-ku8sN9773iIBvlXFdo7EM6Vc3hNYzC9Lg3X9xhnmExkHg6hNeZadc2VoVQ82PtRXKW-oh3m30tb3GnOqXcLlQKMldZvomEDvKssp8iPflAIDqOdmR2Ik#_ = _ – Dustin

相關問題