1

I know it might be duplicate question but please help. I have created a app and installed it on my Facebook page. My issue when I authenticate it using authentication method I got the user id... But when I go through proper signed request method (i.e. When I login with facebook site only.) I don't get user. how can I get userid in case of signed request that When I login using facebook site.

My signed request.

   $facebook = new Facebook(array(
            'appId' => '****',
            'secret' => '****',
            'cookie' => true,
        ));

        echo 'User ID :- ' . $user = $facebook->getUser();
        $signed_request = $facebook->getSignedRequest();

        echo '<pre>';
        print_r($signed_request);
        echo '</pre>';


User ID :- 0
Array (
[algorithm] => HMAC-SHA256
[issued_at] => 1372676199
[page] => Array
    (
        [id] => 544896778905441
        [liked] => 
        [admin] => 1
    )

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

How can I get User id.

Sankalp
  • 1,300
  • 5
  • 28
  • 52

2 Answers2

0

** EDIT ** As of a few months ago (Dec 2014) Facebook no longer allows Like-Gating content. I guess that's why someone is going around placing negative votes and links to their own answers. So the below is no longer valid

There is a difference between getting a signed_request for a user who has authorised an app, which is your first case and getting the user id from a signed request on a page app. In the second example you can test if a user likes your page, but you can't get the specific user id. They are just interacting with your page - yes they may be logged into Facebook, but they haven't explicitly authorised your app. I presume this is what you mean by "login with Facebook site only"

If you look at https://developers.facebook.com/docs/reference/login/signed-request/ you will see it states

Some fields and values, the user_id and oauth_token for example will only be passed if the user has logged into your app.

They may be logged into Facebook, but not have logged in/authorised your app

TommyBs
  • 9,354
  • 4
  • 34
  • 65
-1

You can follow the instruction on how to decode the signed request here https://developers.facebook.com/docs/facebook-login/using-login-with-games#parsingsr

OR

You can use the service that I created. It will return decoded signed request :)

https://websta.me/fbappservice/parseSignedRequest/<concat signed request here>

//angularjs

 you may get it via $http.jsonp(url);

//jquery // refer to jquery docs on getting jsonp requests

$.getJSON( url, {
    format: "json"
  })
Emil Reña Enriquez
  • 2,929
  • 1
  • 29
  • 32