我创建了一个页面选项卡 Facebook 应用程序,我想根据用户是否是粉丝来显示不同的内容。 (也称为扇门、登陆页面或展示页面)
为此,我使用 PHP SDK,具体如下代码:
<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
'cookie' => true,
));
?>
在内容中:
<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["page"]["liked"])) {?>
Thank you for liking our Page!
<?php } else { ?>
You haven't liked our page yet..
<?php };
// Debugging Code
echo "REQUEST:<br>";
print_r($_REQUEST);
echo "<br>GET:<br>";
print_r($_GET);
echo "<br>POST:<br>";
print_r($_POST);
?>
当我使用 Facebook 用户登录并使用它时,这会起作用在我自己的页面上。
这意味着signed_request 存在于$_POST 和$_REQUEST 中。
但是,当我与另一个用户一起测试它时,这些变量中没有signed_request值。
注意:
- 我已经查看了应用程序配置中的 URL 设置(300 重定向等),但这看起来很好,就像我对我的用户所说的那样,它正在工作。
-signed_request 不只是空的,它甚至不存在。
有人有类似的问题吗?
如果可以的话,我不介意使用 Javascript SDK 而不是 PHP,但我在 Javascript 方面经验不是很丰富。
编辑:
据我发现,您始终必须有一个非安全 (http) 和一个安全 (https) URL。
即使您输入安全 URL 作为标准 URL,Facebook 也会使用 http 联系它,然后重定向(取决于服务器配置)到 https,这会使您丢失签名请求。
I have created a Page Tab Facebook App where I want to display different content depending on the user being a fan or not. (Also called fan gate, landing page or reveal page)
For this I'm using the PHP SDK, in specific the following code:
<?php
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
'cookie' => true,
));
?>
And in the content:
<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["page"]["liked"])) {?>
Thank you for liking our Page!
<?php } else { ?>
You haven't liked our page yet..
<?php };
// Debugging Code
echo "REQUEST:<br>";
print_r($_REQUEST);
echo "<br>GET:<br>";
print_r($_GET);
echo "<br>POST:<br>";
print_r($_POST);
?>
This works when I'm logged in with my Facebook User and when I use it on my own Page.
Meaning the signed_request is present in both $_POST and $_REQUEST.
However, when I test it with another user, there is no signed_request value in those variables..
Notes:
- I already took a look at my URL Settings in the App Configuration (300 Redirect and stuff) but this looks fine, and like I said with my User it's working..
- the signed_request is not just empty, it doesn't even exist.
Does anybody have similar issues?
I would not mind using the Javascript SDK instead of PHP if it works then, but I'm not very experienced in Javascript.
EDIT:
As i found out you always have to have a non-secure (http) and a secure (https) URL.
Even if you enter a secure URL as the standard URL, facebook will contact it using http and will then get redirected (depends on server configuration) to the https, which makes you lose your signed_request.
发布评论
评论(2)
我刚刚遇到了类似的问题。就我而言,问题是在应用程序配置中,我没有在引用目录(其中包含 index.php)的选项卡 URL 末尾添加斜杠。所以我得到了一个重定向到相同的 URL,末尾有一个斜杠,并以这种方式丢失了 $_POST 。
I just had a similar problem. In my case the problem was that in the app config i had not put a slash at the end of the tab URL which was referencing a directory (with an index.php in it). So i got a redirect to the same URL with a slash at the end and lost the $_POST this way.
signed_request
永远不会通过GET
传递,而是通过POST
传递。$_REQUEST
根据php.ini
中的配置包含数据 (request_order
或variables_order
)由于您使用的是 PHP-SDK,因此最好将其用于
signed_request
检索:对于在页面选项卡中运行的应用程序
signed_request
始终会被传递,因此如果您没有收到它,请确保没有重定向忽略正在传递的POST
数据。signed_request
is never passed viaGET
butPOST
.$_REQUEST
contain data according to configuration inphp.ini
(request_order
orvariables_order
)Since you are using PHP-SDK it's better to use it for
signed_request
retrieval:For applications running in Page Tab
signed_request
is always passed, so if you not get it ensure there is no redirections that omitPOST
data being passed.