woutr_be
woutr_be

Reputation: 9722

How to check if a Facebook app is loaded outside the canvas

Is it possible to check if an app is loaded inside the canvas or not? I only want people to use my app inside the Facebook canvas, and not outside.

I'm using the Facebook Javascript SDK, while reading about the signed_request (http://developers.facebook.com/docs/howtos/login/signed-request/), I saw that a signed_request is POSTed when the app is loaded inside the canvas.

However I can't find any way to check this in Javascript, when using FB.getLoginStatus, there is always a signed_request, no matter if it's inside the canvas or not.

Upvotes: 0

Views: 949

Answers (1)

Bryan Gentry
Bryan Gentry

Reputation: 873

It looks like you have found the solution: You have to use PHP (or whichever server-side language you are using) to determine whether the page is being viewed through Facebook.

For those who have not figured it out, you use PHP to determine whether the variable signed_request was posted to the page. If it was not, then you can redirect to the appropriate Facebook page, or take other action as desired.

<?php
//if signed_request was not posted...
    if ( !isset ($_POST['signed_request'] ) ) 
        {
        $redirect = 'http://apps.facebook.com/exampleapp'; //the URL of your Facebook canvas app
        header('Location:'.$redirect); //redirect the browser there
        }
?>

Upvotes: 1

Related Questions