具有多个 PHP 页面的 Facebook 应用程序
我正在使用 PHP 和 Facebook SDK 构建一个 iframe 应用程序。第一页上有一个“下载”按钮,链接到第二页。在第二页上,我使用以下代码:
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
if ($like_status) {
include('download.php');
}
else {
include('non-fan.php');
}
我只想为喜欢我们 Facebook 页面的人提供下载。由于某种原因 $signed_request 变量为空。我该如何解决这个问题?
I'm building an iframe application with PHP and the Facebook SDK. On the first page there's an "download" button which links to the second page. On the second page I use the following code:
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
if ($like_status) {
include('download.php');
}
else {
include('non-fan.php');
}
I want to provide the download ONLY for people who liked our Facebook page. For some reason the $signed_request variables are empty. How can I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 iframe 中,Facebook 仅在整个页面初始加载时发布签名请求。 iframe 内的后续页面加载将不会收到该帖子。
您可以序列化签名的请求变量并将其存储在会话中,然后在每次页面加载时检查是否有新的请求变量,如果没有,则从会话中获取它。
In the iframe, Facebook only posts the signed request on the initial load of the whole page. Subsequent pageloads within the iframe won't receive the post.
You can serialize the signed request variable and stash it in your session, then on each pageload check if you've got a fresh one, and if you haven't then grab it from your session.