你好,你们可以解释一下创建一个链接到facebook标签内某个页面的网址吗?
我的这个标签有index.php page1.php page2.php
我想创建一个链接,我可以与我的用户分享,直接将他们引导到page2.php。
我看到我要在app_data上传递一个字符串但是我怎么能把它取回来?因为我的想法是:http://facebook.com/app_id&app_data=gotosomewhere
if(gotosomewhere)
header location
但我无法弄清楚如何获取app_data。
感谢。
答案 0 :(得分:1)
您要查找的参数将放在第一次加载时传递给您的应用程序的signed_request
内。
There is a page in the documentation说明了在检查signed_request时您可能会看到哪些字段。
app_data - 包含app_data查询字符串参数内容的JSON字符串,如果在页面标签页中加载应用程序,则该参数可以传递。
答案 1 :(得分:0)
如果有人需要,这就是解决这个问题的方法。
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, '-_', '+/'));
}
?>
现在我的fangate(index.php)里面有:
<?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;
?>