验证后重定向到Facebook页面选项卡 [英] Redirect to Facebook page tab after authentication

查看:167
本文介绍了验证后重定向到Facebook页面选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Facebook页面,我添加了我的应用程序的选项卡。我用来检查用户是否通过以下代码验证: -

 <?php 
$ app_id =我的APP ID;

$ canvas_page =我的CANVAS PAGE;

$ auth_url =https://www.facebook.com/dialog/oauth?client_id=
。 $ app_id。 & redirect_uri =。进行urlencode($ canvas_page);

$ signed_request = $ _REQUEST [signed_request];

list($ encoded_sig,$ payload)= explode('。',$ signed_request,2);

$ data = json_decode(base64_decode(strload($ payload,'-_','+ /')),true);

if(empty($ data [user_id])){
echo(< script> top.location.href ='$ auth_url。'< /脚本>中);
} else {
echo(< script> location.href ='index.php'< / script>);
}
?>

现在,作为 CANVAS PAGE 必须是相同的 CANVAS PAGE 我在应用程序中更改了页面重定向到 https://apps.facebook.com/myappname/ ,但我希望它重定向到我的Facebook页面选项卡;至此 - https://www.facebook.com/myfbpage/app_82136128736123

解决方案

你是对的。 redirect_uri必须是应用程序拥有的URL。这意味着它在应用程序设置中列出。



您的画布页面必须使用JavaScript重定向(如您正在使用的重定向)。唯一的区别是,您需要记住,您的应用程序是在iframe内运行的。您必须更改顶部的位置属性,而不是文档。顶部引用页面上最顶层的框架,这是应用程序执行正确重定向的唯一方法。

  echo < script language = javascript>; 
echotop.location.href ='$ page_url。';;
echo< / script>;
exit();

这很丑,很多人拒绝相信这是正确的方法,但我是还没找到一个选择。


I have a facebook page where I have added a tab of my application. I use to check that the user is authenticated or not using the following code:-

<?php
     $app_id = "MY APP ID";

     $canvas_page = "MY CANVAS PAGE";

     $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page);

     $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 {
            echo("<script> location.href='index.php'</script>");
     } 
?>

Now as CANVAS PAGE has to be the same CANVAS PAGE I have changed in the application, after logging in page redirects to https://apps.facebook.com/myappname/, but I want it to redirect to my Facebook page tab; To this one - https://www.facebook.com/myfbpage/app_82136128736123.

解决方案

You are correct. The redirect_uri has to be a URL that is "owned" by the application. That means that it is listed in the applications settings.

Your canvas page will have to use a JavaScript redirect (like the one you are using). The only difference is that you need to remember that your application is running inside of an iframe. You'll have to change the location property of top as opposed to the document. Top references the top most frame on the page and that is the only way for an application to perform a proper redirect.

echo "<script language=javascript>";
echo "top.location.href ='".$page_url."';";
echo "</script>";
exit();

It's ugly and many people refuse to believe that this is the correct way to do it, but I am yet to find an alternative.

这篇关于验证后重定向到Facebook页面选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆