Search code examples
facebookfacebook-likefacebook-appsuserid

facebook tab userid is 0 after page like


I'm trying to get a the facebook userid in a facebook tab, but somehow this always returns 0. This is the code I use:

$config = array();
$config["appId"]    = "427761887242287";
$config["secret"]   = "xxxxxxxxxxxxxxxxxxxxxx";
$facebook           = new Facebook($config);
$fbData             = $facebook->getSignedRequest();

Facebook appId and secret are valid, I've already tried with resetting the secret. I've tried to do a print_r on $fbdata but this only returns:

Array

( [algorithm] => HMAC-SHA256 [issued_at] => 1337603346 [page] => Array ( [id] => 158282080958121 [liked] => 1 [admin] => )

[user] => Array
    (
        [country] => nl
        [locale] => en_US
        [age] => Array
            (
                [min] => 21
            )

    )

)

As you can see, this retuns only some non usefull data as far as the user goes. I've also tried $facebook->getUser() but this does return 0. I do have a valid SSL certificate on my server, I use the right http and https URL's but I can't find out why I get a 0 for the userid while I'm logged in. Any suggestions?


Solution

  • If this is a facebook page tab application, then the user id is not returned unless the user has explicitly authorized your application. And from the response you've posted it looks like this is the case. You would need to get the user to authorize your application, not just like a page for this to work

    https://developers.facebook.com/docs/authentication/pagetab/