Facebook getSignedRequest 并不总是获取页面 ID
我正在开发一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我终于明白了这一点。我的代码没有任何问题。问题出在服务器上。它被设置为将所有 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.
我在heroku上的facebook选项卡应用程序中遇到了同样的问题,问题出在示例代码index.php
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
header('Location: https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
The redirection was making page info array to desapear. Without this everything works :)
我遇到了同样的问题,上网冲浪几个小时后,我发现问题出在我的应用程序秘密 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