在Facebook iframe-app中未收到signed_request [英] Not receiving signed_request in Facebook iframe-app
问题描述
我创建了一个Page Tab Facebook App,其中我想根据用户是否是粉丝来显示不同的内容. (也称为风扇登机口,着陆页或展示页)
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)
为此,我正在使用PHP SDK,具体来说,以下代码:
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,
));
?>
在内容中:
<?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用户登录时以及在我自己的Page上使用它时,此方法有效. 这意味着在$ _POST和$ _REQUEST中都存在signed_request.
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.
但是,当我与另一个用户进行测试时,这些变量中没有signed_request值.
However, when I test it with another user, there is no signed_request value in those variables..
注意: -我已经查看了应用程序配置"中的"URL设置"(300重定向和内容),但这看起来还不错,就像我对我的用户说的那样,它可以正常工作. -signed_request不仅为空,甚至不存在.
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.
有人有类似的问题吗?
如果可以的话,我不介意使用Javascript SDK而不是PHP,但是我对Javascript的经验不是很丰富.
I would not mind using the Javascript SDK instead of PHP if it works then, but I'm not very experienced in Javascript.
正如我发现的那样,您始终必须拥有一个非安全(http)和一个安全(https)的URL. 即使您输入安全的URL作为标准URL,facebook也会使用http与它联系,然后将重定向到https(取决于服务器配置),这使您丢失了signed_request.
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.
推荐答案
signed_request
从未通过GET
传递,而是通过POST
传递. $_REQUEST
根据php.ini
中的配置包含数据( request_order
或 variables_order
)
signed_request
is never passed via GET
but POST
. $_REQUEST
contain data according to configuration in php.ini
(request_order
or variables_order
)
由于您使用的是PHP-SDK,因此最好将其用于signed_request
检索:
Since you are using PHP-SDK it's better to use it for signed_request
retrieval:
$signed_request = $facebook->getSignedRequest();
$liked = $signed_request['page']['liked'];
对于在页面"选项卡中运行的应用程序,始终会传递signed_request
,因此,如果未获得该信息,请确保没有重定向忽略忽略正在传递的POST
数据.
For applications running in Page Tab signed_request
is always passed, so if you not get it ensure there is no redirections that omit POST
data being passed.
这篇关于在Facebook iframe-app中未收到signed_request的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!