我们使用了最新版本的 php-sdk 3
<?php
try{
include_once "connect.php";
}
catch(Exception $o){
echo '<pre>';
print_r($o);
echo '</pre>';
}
if (isset($_GET['code'])){
header("Location: " . $appsurl);
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
$uid = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'publish_stream'
)
);
if ($uid) {
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 (!$uid) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
//get user basic description
$userInfo = $facebook->api("/$uid");
function d($d){
echo '<pre>';
print_r($d);
echo '</pre>';
}
?>
我们允许应用程序(转到应用程序)并允许发布到墙上。
允许帖子上墙后,它不会重定向应用程序 url($appsurl)。它会像这样显示
https://[hostingurl]/?state=7f76eb2ad732398827215d86f946a690&code=AQBZ2nsbbs3lfBSBwr_HzFpcKIIZlfjAijl9db7wyn1xEIZ4-W7BqQbFtnVZ8UM_4nQ9qIk57msjw6RlLb6VQqGrF3nupBFoEmrypAPmftAsS4ILW9LEJA5gzTMb2VJhwBHHqSpwGHUbh98bNQQQxkX50Ns5kVaffUUylXrIgy6MQcLxU66hQS7qMImHg5Mi2tUrpPqlWbZNQzlooMkv1WAt#_=_
我们也尝试了 indexpage 中的重定向代码。
if (isset($_GET['code'])){
header("Location: " . $appsurl);
exit;
}
但重定向没有发生。
请你帮助我好吗?