Redirect iFrame apps for Facebook

I am writing a Facebook application that is designed to be displayed through a page tab on my own business page. I need to interact with the viewer user, so I need advanced permissions.

I followed the suggested procedure, but now hit the wall. My application is in an iFrame, and the extended rights request uses redirection. I can get a page on which you need to confirm authorization, but when you click "Allow", Facebook redirects the page where my application is placed, and not back to my tab on the Facebook page. Once the correct rights have been resolved, the rest of the application works fine, so I know this is just a redirect problem, but I feel like I tried everything and many people did not seem to have the same problem. I wish someone could point me in the right direction.

Thanks!

Here is my code:

$app_id = "myappid"; $canvas_page = "http://wheremyappishosted/"; $signed_request = $_REQUEST["signed_request"]; list($encoded_sig, $payload) = explode('.', $signed_request, 2); $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true); $user_id = $data["user_id"]; $access_token = $data['oauth_token']; if (empty($data["user_id"])) { $auth_url = "https://graph.facebook.com/oauth/authorize?client_id=".$app_id."&redirect_uri=".urlencode($canvas_page)."&scope=user_photos,friends_photos,publish_stream,user_likes"; die("<script> top.location.href='" . $auth_url . "'</script>"); } $f = json_decode(file_get_contents("https://graph.facebook.com/".$user_id."?access_token=".$access_token."&fields=name,albums,likes"), true); 
+1
source share
4 answers

For those who are interested, I believe that I have found a way around this. Instead of redirecting the user back to the application, I redirect them to a small script, which then redirects back to the page tab. Since the application is already allowed, everything works, and signed_request is passed along with the user information. I don’t know if this is really a legal way, but it works.

+4
source

Set the redirect variable to the landing page:

 $redirect = "http://foo.com"; 
0
source

Set redirect_uri to "http [s]: //apps.facebook.com/YOUR_APP/" instead of "http [s]: //apps.facebook.com/YOUR_APP". Pay attention to the end slash!

0
source

I found out that using javascript sdk is much better when unsolved redirection problems arise using server-side scripts, implement this little test, and you will realize that most of the things happen using the lightbox, that is, over your application. which keeps the application page intact.

https://developers.facebook.com/docs/facebook-login/getting-started-web/

0
source

Source: https://habr.com/ru/post/1335374/


All Articles