Facebook $ facebook-> getSignedRequest (); error

I am trying to add this script to my iframe application on facebook, but it does not seem 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 posting the correct app id and private key and im calling facebook.php in the right way. I am not getting any errors or warnings, just the script is not working.

$like_status nothing

has the script changed? is there any other version? thanks

to change. 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"; ?> 
+3
source share
6 answers

Facebook sends a 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); 
+3
source

I had a similar problem a while ago - the solution was to provide the full URL for the tab page or / and canvas to receive a signed request.

Example: use http://myapp.com/myapp/index.php , isntead http://myapp.com/myapp/

+10
source

$_REQUEST['signed_request'] may be empty if your canvas (or page tab) is not the last and redirects to some other URL because Facebook sends the signed request only once. When redirecting, the lost value is lost.

If you have some redirection control, add ?signed_request=$_REQUEST['signed_request'] to your redirected URL (you may also need to pass other custom GET parameters)

+2
source
  • What is the facebook php sdk version?
  • check access_log and error_log on your web server
  • Do you have the missing ";"?
0
source

Not sure what is wrong here, but here is the base page on which it will work. Make sure the latest version of facebook.php and base_facebook.php are in the same directory. You can find sdk here: https://github.com/facebook/php-sdk In addition, do not forget to specify your application identifier and secret where you are all 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> 

0
source

Unfortunately, I had the same problem. After hours and hours trying to solve it, I finally created a new application with exactly the same setting. I updated the key and secret in my code for new and voilร  - running it as a charm on the first try.

Definitely a problem with Facebook. Perhaps dropping the application id and privacy might also work, but I have not tried this first.

0
source

All Articles