我使用 PHP SDK 让用户授权我的应用程序。有点棘手的是我正在标签内执行此操作。重定向 uri 将打破标签“iframe”并作为普通应用程序打开,我不想要这个。我怎样才能将它保存在页面选项卡 iframe 中。下面是我的代码;
<?php
include("utility.php");
include("db_setup.php");
require_once "base_facebook.php";
require("facebook.php");
$facebook = new Facebook(array(
'appId' => 'xxxxxx',
'secret' => 'xxxxxx',
));
$conn = connectUserDB();
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
//$user_profile = $facebook->api('/me?fields=name,id,email');
header( 'Location: submitted.php' ) ;
} catch (FacebookApiException $e) {
//print_r($e);
$user = null;
}
}
// $user is null : $user is either not logged in or the token is not valid
else if(!$user) {
$params = array(
'scope' => 'email',
'redirect_uri' => 'submitted.php'
);
$loginUrl = $facebook ->getLoginUrl($params);
echo '<script type="text/javascript">';
echo 'top.location.href = " '.$loginUrl.' " ; ';
echo '</script>';
}
?>