在 Facebook iframe-app 中未收到signed_request

发布于 2025-01-03 08:09:47 字数 1321 浏览 0 评论 0 原文

我创建了一个页面选项卡 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌路黄昏 2025-01-10 08:09:47

我刚刚遇到了类似的问题。就我而言,问题是在应用程序配置中,我没有在引用目录(其中包含 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.

雨的味道风的声音 2025-01-10 08:09:47

signed_request 永远不会通过 GET 传递,而是通过 POST 传递。 $_REQUEST 根据 php.ini 中的配置包含数据 (request_ordervariables_order)

由于您使用的是 PHP-SDK,因此最好将其用于 signed_request 检索:

$signed_request = $facebook->getSignedRequest();
$liked = $signed_request['page']['liked'];

对于在页面选项卡中运行的应用程序 signed_request 始终会被传递,因此如果您没有收到它,请确保没有重定向忽略正在传递的 POST 数据。

signed_request is never passed via GET but POST. $_REQUEST contain data according to configuration in php.ini (request_order or variables_order)

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'];

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文