所以基本上我试图让一个像门一样工作,但$ like_status变量永远不会改变所以我改变到喜欢的内容的条件永远不会工作。有谁知道为什么这永远不会改变?已将我的应用程序添加到Facebook上的页面选项卡,它获取所有其他变量$ page_id,$ page_admin,$ country和$ locale但不是$ like_status。
谢谢查理
请参阅下面的代码
<?php
enter code here
require_once('AppInfo.php');
// Enforce https on production
if (substr(AppInfo::getUrl(), 0, 8) != 'https://' && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
header('Location: https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}
// This provides access to helper functions defined in 'utils.php'
require_once('utils.php');
require 'includes/facebook.php';
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => AppInfo::appID(),
'secret' => AppInfo::appSecret(),
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];
echo "<br>page id = $page_id";
echo "<br>page admin = $page_admin";
echo "<br>like status = $like_status";
echo "<br>country = $country";
echo "<br>locale = $locale";
function grokSignedRequest()
{
if (isset($_REQUEST['signed_request']))
{
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
// call the function to parse the signed request
$sr_data = grokSignedRequest();
// check like status
if ($sr_data->page->liked==1)
{
include ('includes/index2.php');
}
else
{
include ('includes/index1.php');
}
?>
答案 0 :(得分:1)
如果您在标签页上运行PHP代码,like_status
可能实际存在,但设置为0(零)。因此,echo
语句似乎不为$like_status
输出任何内容,但实际上,它的值为零。为了证明这一点尝试这样的代码:
if ($like_status == 0)
echo "it's zero";
else
echo "it's not zero";
答案 1 :(得分:0)
编辑:对不起,我没有看到@robbie在问题的评论中解决了这个问题
用户必须从页面标签到达应用程序,并且:
与Canvas页面一样,在用户授权您的应用之前,您不会在signed_request中收到应用可访问的所有用户信息。
https://developers.facebook.com/docs/appsonfacebook/pagetabs/#integrating