Reputation: 27038
i am trying to add this script to my iframe app on facebook but it seems not to work:
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
// If a fan is on your page
if ($like_status) {
echo 123;
} else {
// If a non-fan is on your page
echo 456;
}
i am placing the right app id and secret key and im calling facebook.php the right way. I get no errors or warnings, just that the script doesn't work.
$like_status
doesn't return anything
did the script changed? is there another version? thanks
edit. more code:
<?php
require 'facebook.php';
$app_id = "11549508592";
$app_secret = "d898cb58b16f2aaaaaaaaaaaaaa";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
echo "<br>like status = $like_status";
?>
Upvotes: 3
Views: 12471
Reputation: 1075
Unfortunately, I had the same issue. After hours and hours trying to solve it, I finally created a new application, with exactly the same set up. I updated key and secret in my code to the new ones and voilà - its running like a charm from the first attempt.
Definitly a Facebook issue. Maybe resetting App ID and secret could also had worked, but I didn't try that first.
Upvotes: 0
Reputation: 6159
$_REQUEST['signed_request']
could be empty if your canvas (or page tab) URL is not the final one and redirects to some other URL because Facebook posts the signed request only once. When redirecting, the posted value is lost.
If you have some control over the redirection, then add ?signed_request=$_REQUEST['signed_request']
to your redirected URL (you might also need to pass other custom GET parameters)
Upvotes: 2
Reputation: 341
I had similar problem a while ago - the solution was to specify full url for tab or/and canvas page to receive signed request.
Example: use http://myapp.com/myapp/index.php, isntead of http://myapp.com/myapp/
Upvotes: 10
Reputation: 2588
Not sure whats wrong here, but here is a basic page that it will work on. Make sure that the latest version of facebook.php and base_facebook.php is in the same directory. You can find the sdk here: https://github.com/facebook/php-sdk Allso remember to put in your app id and secret where you se all the 111111111111111's
<?php
require 'facebook.php';
$app_id ="11111111111111111";
$app_secret = "11111111111111111111111111";
$facebook = new facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>untiteled</title>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.Canvas.setSize();
}
</script>
</head>
<body>
<div class="wrapper">
<?php if(!$like_status):?>
<div class="likearrow"><div><div></div></div></div>
<p id="like">Click "<b>like</b>" if you want to become a fan of this app</p>
<?php endif; ?>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId: '111111111111111111111',
status: true,
cookie: true,
xfbml: true
});
</script>
</body>
Upvotes: 0
Reputation: 119
Upvotes: 0
Reputation: 1410
Facebook sends the signed request to your page when it is called from facebook.
So:
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
Upvotes: 3