Suraj Malinga
Suraj Malinga

Reputation: 101

How to get signed request in Facebook SDK v 4

I created a tab app on facebook using Facebook sdk 4. I could get session info as follow.

 Facebook\FacebookSession Object
(
    [token:Facebook\FacebookSession:private] => xxxxxxxxxxxxx
    [signedRequestData:Facebook\FacebookSession:private] => Array
        (
            [algorithm] => HMAC-SHA256
            [expires] => 1401951600
            [issued_at] => 1401947659
            [oauth_token] => xxxxxxxxxxx
            [page] => Array
                (
                    [id] => 1503486xxxxxxxx
                    [liked] => 
                    [admin] => 1
                )

            [user] => Array
                (
                    [country] => lk
                    [locale] => en_GB
                    [age] => Array
                        (
                            [min] => 21
                        )

                )

            [user_id] => 85219xxxxxxxxxxxx
        )

)

I want to check user already liked the page or not. i tried in this way.

if($session['page']['liked'] == 1){
     echo "user liked the page";
}else{
     echo "not liked";
}

but didn't work.

Upvotes: 1

Views: 3950

Answers (3)

Hammad Haleem
Hammad Haleem

Reputation: 1394

This doesn't work anymore, because Facebook is discouraging "Like-gating" content.

See

https://developers.facebook.com/docs/apps/changelog#v2_1_90_day_deprecations The 'liked' property will no longer be returned in the 'signed_request' object for Page Tab apps created after today. From November 5, 2014 onwards, the 'liked' property will always return 'true' regardless of whether or not the person has liked the page.

https://developers.facebook.com/docs/facebook-login/permissions/v2.1#reference-user_likes As you'd need the user_likes permission to determine whether a user has likes the page, and thereby need an app review, you'll very likely not be able to get the permission approved:

Not allowed: Gate access to your app, or some content within your app based on whether or not someone has liked a page.

Upvotes: 3

J.T.
J.T.

Reputation: 135

This is no longer supported: Graph API v2.1 and updated iOS and Android SDKs

The liked field is no longer returned in the page property of the signed_request object. So I guess no more forcing the users to like the page to get to tab content...

Upvotes: 1

Fosco
Fosco

Reputation: 38526

Try this:

$pageInfo = $session->getSignedRequestProperty('page');
if ($pageInfo['liked'] == 1) {

This was just implemented on Friday: https://github.com/facebook/facebook-php-sdk-v4/pull/97

It should be in version 4.0.7.

$helper = new FacebookPageTabHelper();

$user_liked = $helper->isLiked(); 

Upvotes: 2

Related Questions