我已经创建了一个facebook应用程序,当它从apps.facebook.com/myapp
完全打开到我的域名的index.php并且可以在facebook应用程序窗口中看到,但是当我尝试将其重定向到我的注册页面时出现问题,它被重定向到我的域,我希望在Facebook应用程序窗口中查看所有页面。尝试使用fb:redirect sdk函数,但网站表示他们将弃用这些代码。
<?php
if(preg_match('/apps.facebook.com/',$_SERVER[HTTP_REFERER])){
$app_id = '';
$api_key = '';
$app_secret = '';
$canvas_page = 'mydomain/index.php';
$auth_url = "http://www.facebook.com/dialog/oauth?client_id=".
$app_id."&redirect_uri=".urlencode($canvas_page)."&scope=email,user_birthday,user_interests,user_about_me";
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload,'-_', '+/')), true);
if (empty($data["user_id"])){
echo("<script> top.location.href='".$auth_url ."'</script>");
}else{
$canvas_page="mydomain/register.php";
echo ("<script> top.location.href='".$auth_url."'</script>");
}
}else{
echo "No facebook";
}
?>
这个代码可以完美地工作到echo("<script> top.location.href='" .$auth_url ."'</script>")
,当{app}开发形式中设置$canvas_page
时;但是当$canvas_page
更改为我的register.php页面时,会被重定向到其他页面。我哪里错了?
提前致谢
答案 0 :(得分:5)
<?php
//facebook application
//set facebook application id, secret key and api key here
$fbconfig['appid' ] = "123456392899383";
$fbconfig['api' ] = "97eb2asdfasdf3f20d4421b0fe8c1b2";
$fbconfig['secret'] = "5c1d4asdfasdf71b59806b69c386b2ca";
//set application urls here
$fbconfig['baseUrl'] = "http://www.your-url.com/";
$fbconfig['appBaseUrl'] = "http://apps.facebook.com/appname/";
$uid = null; //facebook user id
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
$session = $facebook->getSession();
$loginUrl = $facebook->getLoginUrl(
array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'email,publish_stream,status_update,user_birthday,user_location,user_work_history'
)
);
$fbme = null;
if (!$session) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
else {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
//PUT THE APPLICATION CODE HERE>
} catch (FacebookApiException $e) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
}
function d($d){
echo '<pre>';
print_r($d);
echo '</pre>';
}
?>
您可以使用此脚本正确授权应用程序定期使用它。
答案 1 :(得分:0)
你的$ auth_url不会改变:
$canvas_page="mydomain/register.php";
echo ("<script> top.location.href='".$auth_url."'</script>");
$ auth url仍然是在顶部定义的url $ canvas_page ='mydomain / index.php';
答案 2 :(得分:-4)
这与facebook
无关。这是ABC PHP !!!
<?php
$a = "John";
$b = "Hello " . $a;
$a = "Bob";
print $b; // returns: Hello John
$b = "\nHello " . $a;
print $b; // returns: Hello Bob
?>
直播example。