Stefano Cerelli
Stefano Cerelli

Reputation: 105

Link to a specific page inside facebook TAB

Hallo guys can you pls explain me a way to create an url that link to a certain page inside a facebook tab?

I've this tab with index.php page1.php page2.php

i want to create a link that i can share with my users that lead them directly to page2.php.

I saw that i've to pass a string on app_data but then how can i get it back? cause my idea was this: http://facebook.com/app_id&app_data=gotosomewhere

if(gotosomewhere)
  header location

but i can't figure out how to get app_data.

Thanks.

Upvotes: 0

Views: 190

Answers (2)

Stefano Cerelli
Stefano Cerelli

Reputation: 105

If anyone needs, this is the way solved this problem.

facebook_data.php:

    <?php
    define('APP_ID',      'hereyourappid');
    define('APP_API_KEY', 'hereyourappid');
    define('APP_SECRET',  'hereyoursecretappid');
    error_reporting(0) ; 


    $signed_request = parse_signed_request(@$_REQUEST['signed_request'], APP_SECRET);
    defin

e('LIKED', @$signed_request['page']['liked']);

$app_data = $signed_request['page']['liked'];
$redirect = $signed_request['app_data']; /* HERE I DECLARE A VARIABLE 
THAT GET THE PARAMETER I PASS VIA URL */
$fanGate=LIKED;

function parse_signed_request($signed_request, $secret) {
  list($encoded_sig, $payload) = @explode('.', $signed_request); 

  // decode the data
  $sig = base64_url_decode($encoded_sig);
  $data = json_decode(base64_url_decode($payload), true);

  if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
    error_log('Unknown algorithm. Expected HMAC-SHA256');
    return null;
  }

  // check sig
  $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
  if ($sig !== $expected_sig) {
    error_log('Bad Signed JSON signature!');
    return null;
  }

  return $data;
}

function base64_url_decode($input) {
  return base64_decode(strtr($input, '-_', '+/'));
}

?>

Now inside my fangate (index.php) i do:

<?php 
header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
header("Set-Cookie: SIDNAME=ronty; path=/; secure");
header('Cache-Control: no-cache');
header('Pragma: no-cache');
@session_start();
include('includes/facebook_data.php.php');


$sezione='fangate';
$pagina = '';
?>

<?php if(!LIKED): ?>
<!DOCTYPE HTML>
<html>
<head>
    <?php include("includes/head.php"); ?>
</style>
</head>
<body>
<?php include("includes/fb.php"); ?>
    <div id="fangate">
            <!-- your fangate -->
            <?php include("includes/footer.php");?>  
    </div>
</body>
</html>
<?php
elseif($redirect == "gotopage"):
    header('Location: page2.php');
else:
    header('Location: homepage.php');
endif;
?>

Upvotes: 0

Lix
Lix

Reputation: 47976

The parameter you are looking for will be placed inside the signed_request that is passed to your application the first time it is loaded.

There is a page in the documentation that talks about what fields you can expect to see when inspecting your signed_request.

app_data - A JSON string containing the content of the app_data query string parameter which may be passed if the app is being loaded within a Page Tab.

Upvotes: 1

Related Questions