简体   繁体   中英

Facebook getSignedRequest not always grabbing 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?

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.

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 :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM