Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to authorize Facebook app using redirect in canvas?

I'm trying to get into making Facebook apps but I'm having trouble getting authorization working in a redirect scheme inside the canvas.

Using the javascript api, I got it working 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 unnecessary extra click, because every other application I see requests the authorization before even showing you the landing page. Like this:

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

I figure they're simply using a redirect scheme. So I spent the entire day trying the different ways I could find:

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 stuff, show a link like this:

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

Hilariously, if I open the iframe's address in a new tab, I get the authorization request like I wanted. But I want it to display immediately, without an extra click, like every other app.

Here's an example of an app that is doing authorization and requesting permissions all in one go, in redirect form, before even displaying the landing page:

www.facebook.com/send.fortune.cookies

How are they doing it?

like image 962
Brandon Avatar asked Aug 01 '10 05:08

Brandon


People also ask

How do I redirect to a specific page in canvas?

The Navigation pane will now display the redirect button you just created. Clicking on it will open the specified page within Canvas. Unsecured content is identified with the prefix http:// in the URL and can create mixed content in your Canvas Page. Secured content is identified with the https:// prefix in the URL.

How to create a Facebook app that automatically redirects to an external link?

Basically, to create a Facebook app that automatically redirects to an external link such as your website we will be creating a file that needs to be uploaded and stored online (you can use your website’s hosting for this) and then linking it to our Facebook page. 1.

How do I add external apps to my Canvas account?

On the left hand Navigation pane, click on Settings, found at the bottom of the Navigation Pane. 3. Now click on the Apps tab and a list of external apps that can be added to Canvas will be displayed. 4. Click on “Redirect Tool” which looks similar to the image below. This will open the page for the app: 5. Click on the blue “Add tool” button:

What is the purpose of a Facebook canvas or page tab?

It should also be noted that in Facebook’s Platform Policy they say: “The primary purpose of your Canvas or Page Tab app on Facebook must not be to simply redirect users out of the Facebook experience and onto an external site.”


1 Answers

I know that this is months old now... but this is what you should 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);
}
like image 108
Jay Moretti Avatar answered Sep 17 '22 22:09

Jay Moretti