Redirect to Facebook page tab after authentication

一个人想着一个人 提交于 2019-12-25 18:31:38

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11973734/redirect-to-facebook-page-tab-after-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!