user971741
user971741

Reputation:

Restricting page tab app to only fans

I’ve just created a facebook app and has added it to my facebook page, all smooth till now, but one thing that I need know is restrict that app to only people who are fans of my page.

But I don’t know how to do it, in other words the scenario I am looking to implement is like this:

if(user is a fan){
    //Show app contents
}
else{
    //Request user to like the page.
}

The code snippet that I am currently using is this, but its not working correctly i.e. returning ‘not liked’ even though ive liked the page:

    $app_id = "160336534418730";
    $app_secret = "b14ac6d2b75656db259599b06983e881";
    $canvas_page = "http://apps.facebook.com/myapp";
    $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . $canvas_page . "&scope=email,read_stream,publish_stream,user_photos";

    //Requesting Signed Parameter:
    $signed_request = $_REQUEST["signed_request"];
    list($encoded_sig, $payload) = explode('.', $signed_request, 2);
    $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

    if ($signed_request -> page -> liked) {
        // They Like us!
        echo "LIKED";
    } else {
        echo "NOT LIKED";
    }

Kindly help me with this. Thank you

Upvotes: 0

Views: 1145

Answers (1)

Thilina Hasantha
Thilina Hasantha

Reputation: 130

Changing your code as below will solve this

if ($data['page']['liked']) {
    // They Like us!
    echo "LIKED";
} else {
    echo "NOT LIKED";
}

Upvotes: 2

Related Questions