Facebook getSignedRequest 并不总是获取页面 ID

发布于 2024-12-18 23:39:16 字数 456 浏览 2 评论 0原文

我正在开发一个 Facebook 应用程序,我想将其用作页面选项卡。这个想法是,它会根据使用选项卡的 Facebook 页面显示不同的内容。

<?php require_once ("php-sdk/facebook.php");
$config = array();
$config['appId'] = 'xxxxx';
$config['secret'] = 'xxxxx';
$facebook = new Facebook($config);
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"]; ?>

不幸的是,它只是偶尔有效。现在,我只是想回显 $page_id,但它并不总是有效。有时它会正确地回显 $page_id,有时它会回显空值。

有什么想法吗?

I'm working on a Facebook app that I'd like to use as a page tab. The idea is that it would display different content based on the Facebook Page the tab is used on.

<?php require_once ("php-sdk/facebook.php");
$config = array();
$config['appId'] = 'xxxxx';
$config['secret'] = 'xxxxx';
$facebook = new Facebook($config);
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"]; ?>

Unfortunately, it only occasionally works. Right now, I'm simply trying to echo out the $page_id, and it doesn't always work. Sometimes it will correctly echo out the $page_id, other times it echoes out a null value.

Any ideas?

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

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

发布评论

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

评论(3

缪败 2024-12-25 23:39:16

我终于明白了这一点。我的代码没有任何问题。问题出在服务器上。它被设置为将所有 http 流量更改为 https 流量。因此,该选项卡正在为设置 Facebook 使用 https 的个人提取 page_id。如果有人使用 http 查看 facebook,它无法提取 page_id。

现在一切都修好了。服务器允许 http 流量保持 http 状态,允许 https 流量保持 https 状态。

I finally figured this out. There is nothing wrong with my code. The problem was on the server. It was set to change all http traffic to https traffic. So, the tab was pulling the page_id for individuals who set up Facebook to use https. It wasn't able to pull in the page_id if someone was viewing facebook using http.

It's all fixed now. The server allows http traffic to stay http and https traffic to stay https.

美男兮 2024-12-25 23:39:16

我在heroku上的facebook选项卡应用程序中遇到了同样的问题,问题出在示例代码index.php

if (substr(AppInfo::getUrl(), 0, 8) != 'https://' && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {

header('Location: https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) ;
出口();

重定向使页面信息数组消失。没有这个一切都会正常:)

I was geting the same problem with facebook tab app on heroku, the problem was at the sample code index.php

if (substr(AppInfo::getUrl(), 0, 8) != 'https://' && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {

header('Location: https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();

The redirection was making page info array to desapear. Without this everything works :)

錯遇了你 2024-12-25 23:39:16

我遇到了同样的问题,上网冲浪几个小时后,我发现问题出在我的应用程序秘密 ID 上,

我希望这有帮助

i had the same problem, after hours surfing the internet i found out the problem was with my app secret ID

i hope this helped

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