How to enable Facebook app using redirect to canvas?

I am trying to connect to Facebook applications, but I am having problems getting authorization working in the redirect scheme inside the canvas.

Using the javascript api, I got it pretty easily in a popup scheme:

$("#loginButton").click(function(e) { FB.login(function(response) { if (response.perms) { perms(); } }, {perms : 'publish_stream'}); 

But the popup should be an extra extra click, because every other application that I see is asking for authorization, even showing you the landing page. Like this:

http://i.imgur.com/yBGzL.png

I suppose they just use a redirect scheme. So I tried all day to find different ways:

 header("Location: https://graph.facebook.com/oauth/authorize?client_id=" . $gAppId . "&redirect_uri=" . urlencode($gUrl) . "&perms=publish_stream"); header("Location: http://www.facebook.com/login.php?v=1.0&api_key=" . $gApiKey . "&next=" . urlencode($gUrl) . "&canvas="); header("Location: http://www.facebook.com/connect/uiserver.php?app_id=" . $gAppId . "&next=" . urlencode($gUrl) . "&return_session=0&fbconnect=0&canvas=1&legacy_return=1&method=permissions.request"); 

But all of them, instead of showing the authorization request material, show a link like this:

http://i.imgur.com/bLwPQ.png

Fun, if I open the iframe address in a new tab, I get the authorization request as I wanted. But I want it to be displayed immediately, without an additional click, as in any other application.

Here is an example of an application that performs authorization and requests permission at a time in the form of a redirect, even showing the landing page:

www.facebook.com/send.fortune.cookies

How do they do it?

+6
redirect authorization facebook
source share
4 answers

I know that this is already several months ... but this is what you must do to add permission checking to your canvas.

 if ($session) { try { $uid = $facebook->getUser(); $me = $facebook->api('/me'); $accesstoken=$session['access_token']; } catch (FacebookApiException $e) { error_log($e); } } if($me) { // do what you have to do }else { $loginUrl = $facebook->getLoginUrl( array( 'canvas' => 1, 'fbconnect' => 0, 'req_perms' => 'publish_stream' ) ); echo '<script>top.location="'.$loginUrl.'";</script>'; //echo '<fb:redirect url="' . $loginUrl . '" />'; //header('Location: '.$loginUrl); } 
+10
source share

The problem is that server-side redirection only redirects your internal application frame instead of redirecting the entire page, and Facebook does not like to show its system dialogs inside frames.

You will need a client side redirect, maybe something like this:

 <script> <?php if($doRedirect) { echo 'top.location="http://redirect_url";'; } ?> </script> 
+6
source share

Using the FB Javascript SDK, you can do something like:

 FB.getLoginStatus(function(response) { if (response.status === 'connected') { loggedIn(response); } else { top.location = encodeURI("https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_APP_URI&response_type=token"); } 
+1
source share

Perhaps this helps:

  if(!$facebook->api_client->users_isAppUser()) { ?> <fb:redirect url="http://www.facebook.com/login.php?v=1.0&api_key=111111111111&next=http%3A%2F%2Fapps.facebook.com%2Fapp_name%2F&canvas=&req_perms=publish_stream"/> <?php } 
0
source share

All Articles