Facebook $signed_request['user_id'] Not Pulling User ID

I've looked around so if this is a re-post, send me in the right direction but I keep getting 1 single random character when I run this. What am I doing wrong? I just want to output the user ID.

 <?php require 'facebook.php';
  $facebook = new Facebook( array( 
   'cookie'  => true
 ) );

 try {
  $me = $facebook->api('/me');
 } catch ( FacebookApiException $e ) {
  error_log( $e );

 $signed_request = $_REQUEST["signed_request"];
 $user_id = $signed_request['user_id'];
 echo $user_id;

 $signed_request = $facebook->getSignedRequest();
 $liked = $signed_request['page']['liked'];


Also the $signed_request['page']['liked'] works just fine.


Is that a copy/paste from your code? If so

 $signed_request = $_REQUEST["signed_request"];
 $user_id = $signed_request['user_id'];
 echo $user_id;

won't work, it's not the correct signed_request and it won't be readable because you haven't decrypted the response (in the PHP SDK the decryption is automatic in the 'getSignedRequest()' function)

The page code you have is correct, so to get the current user ID, assuming that the user has accepted the auth dialog for your app, the code should be

 $signed_request = $facebook->getSignedRequest();
 $user_id = $signed_request['user_id'];
 echo $user_id

Need Your Help

Django, show ValidationError in template

django forms email unique validationerror

I create a registation app, where users can register providing a username, email and a password. What I did is make sure that the email field is unique(as you can see in the code below). But I can't

How does Google implement "Undo" in GMail?

web-applications undo

I've read about how to implement Undo in web applications. There are several drawbacks to this light-weight approach on the client-side.