Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use a mix of server and client side scripts to achieve what you have asked for. Assuming php as your server side language, something like below should work in most of the cases:</p> <pre><code>&lt;?php $app_id = "&lt;your app id&gt;"; $page_url = "&lt;your page url&gt;"; // if your app requires extended permissions $app_scope = "user_interests,publish_actions,publish_stream"; //etc. // depending on your requirement you may use the oauth authentication // or you may simply redirect to your page url instead $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&amp;redirect_uri=" . urlencode($page_url) . "&amp;scope=" . $app_scope; // this is passed only when your page is pulled by facebook if (!isset($_REQUEST["signed_request"])) { // we are sure that the page is not accessed within facebook // so we may redirect header ('Location: ' . $auth_url); // or $page_url die(); } $signed_request = $_REQUEST["signed_request"]; list($encoded_sig, $payload) = explode('.', $signed_request, 2); $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true); // we can check this and redirect later $user_id = $data["user_id"]; // other details are also avialable $user = $data["user"]; $algorithm = $data["algorithm"]; $issued_at = $data["issued_at"]; $oauth_token = $data["oauth_token"]; $expires = $data["expires"]; // passed only when the app is loaded inside a page tab // can be checked for and if empty we can redirect $app_data = $data["app_data"]; // signed_request algorithm's signature verification // is omitted here for simplicity sake. you may perform // that to ensure the authenticity of the request // other initial setups ?&gt; </code></pre> <p>Now you may put the below script inside the <strong><code>&lt;head&gt; &lt;/head&gt;</code></strong> tag on your page:</p> <pre><code>&lt;script type="text/javascript"&gt; &lt;?php if (empty($user_id)): // or as may the need be, you may want to check $app_data instead ?&gt; top.location.href="&lt;?php echo $auth_url; // or you may want to use $page_url instead ?&gt;"; &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload