一旦用户授权我将我的Facebook应用程序重定向回页面上的标签页面,我遇到了很多麻烦。
我的应用程序将在多个页面上生存,因此它不像粘贴重定向的URL那么容易。有没有办法获取页面的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 :(得分:0)
尝试评论此行: echo“top.location.href ='$ loginUrl';”;
我认为登录标签页的默认行为是保留在该标签页上。你不必告诉它去那里。