iFrame应用程序..在用户授权应用程序后重定向回页面选项卡
问题描述:
我有很多麻烦让我的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;
?>
答
尝试注释掉这一行: 回声 “top.location.href = '$ loginUrl';”;
我相信在标签页上登录的默认行为是保留在该标签页上。你不必告诉它去那里。
我评论说,但我的应用程序现在不加载。 – Dustin
每当我删除所有提到这件事把我送到我的应用程序的网页的重定向,有几个查询字符串 的http://本地主机/食品/状态= 05efbcc4c5bf591e56f518ee16a375ce&代码= AQCAlYQpbJmCttiE7nDCxCVOWB6gAg51hpb4LTj2g5zmvylE6_p0sJ8BDRoHH7Z1jwncnUwJGbl-2E-ku8sN9773iIBvlXFdo7EM6Vc3hNYzC9Lg3X9xhnmExkHg6hNeZadc2VoVQ82PtRXKW-oh3m30tb3GnOqXcLlQKMldZvomEDvKssp8iPflAIDqOdmR2Ik#_ = _ – Dustin