当有人访问尚未授权该应用的画布页面时,我从this post获得了帮助,以了解如何重定向到Facebook授权页面。
现在,我希望在用户授权后,FB会重定向到画布页面(https://app.facebook.com/myapp)。但它正在重定向到画布网址(https://myhostingapp.com/game.php?..。)
这是预期的,还是我们可以采取任何措施来控制它。如何在授权后告诉API重定向到画布页面?
现在我可以考虑使用$ _SERVER [HTTP_REFERER]来查看我是否来自授权页面,如果是,则将页面重定向到画布页面。但我希望有更好的方法可以做到这一点
Canvas网址代码:
if (Config::$fbAvailalbe){ //see below how this variable is derived
echo "fb is available";
$facebook = new Facebook(array(
'appId' => Config::$appId,
'secret' => Config::$appSecret,
));
$user = $facebook->getUser();
if ($user) {
echo "app installed";
try {
// Proceed knowing you have a logged in user who's authenticated.
$profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if (!$user) {
echo " app not installed gonna redirect";
$scope = "scope=email,read_stream,read_friendlists,publish_stream";
$redirect = $facebook->getLoginUrl(
array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => $scope
)
);
echo '<script>top.location="' . $redirect . '";</script>';
exit();
//header("Location: $redirect".$scope);
}
if ($profile){
$firstName = $profile['first_name'];
$sid = $profile['id'];
var_dump($profile);
}else{
echo "unable to get profile";
}
}else{
echo "fb unavailable, using dmmy";
$firstName = "Dummy Name";
$sid = Config::$testsid;
}
来自Config.php的Snipet
//this is to derive the $fbAvailable variable
//we get this condition satisfied when we run the page runs from fb canvas
if (isset($_SERVER['HTTP_REFERER'])){
if (substr_count($_SERVER['HTTP_REFERER'],'apps.facebook.com')){
self::$fbAvailalbe = 1;
}
}
答案 0 :(得分:0)