Amir
Amir

Reputation: 2126

How to check user like the facebook Application or not?

How can we check user liked the facebook application or not?

I am trying to create a Facebook app, in it there are two different pages , if user liked then page_1 will be show, otherwise page_2 show.

Upvotes: 2

Views: 10438

Answers (3)

VikasG
VikasG

Reputation: 579

A better approach to the problem can be:

// to generate user access token after the user is logged in
$USER_ACCESS_TOKEN = $facebook->getExtendedAccessToken();

$isFan = curl("https://api.facebook.com/method/pages.isFan?format=json&access_token=" . $USER_ACCESS_TOKEN . "&page_id=" . $FACEBOOK_PAGE_ID);

        function curl($url) {

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            $data = curl_exec($ch);
            curl_close($ch);
            return $data;
        }

Upvotes: 2

Somnath Muluk
Somnath Muluk

Reputation: 57766

<?php 
$user = $facebook->getUser(); 
if ($user) { 

try{ 
$user_profile = $facebook->api('/me');
 $likeID = $facebook->api(array( 'method' => 'fql.query',
 'query' => 'SELECT url FROM url_like WHERE user_id = "'.$user_profile['id'].'" AND url="myurl/"'; )); 
}
 catch(FacebookApiException $e) { }
 } 
if(count($likeID)>0) echo "User likes this page"; 
else echo "User doesn\'t like this page";

?>

credible and/or official sources:

  1. http://www.zuberi.me/2011/how-to-check-if-user-liked-the-application-or-page.html
  2. http://www.chilipepperdesign.com/2011/02/15/reveal-fan-gate-like-gate-facebook-iframe-tab-tutorial-with-php
  3. How to check if a user likes my Facebook Page or URL using Facebook's API
  4. Facebook how to check if user has liked page and show content?
  5. Facebook Check if user "Liked" the page

Upvotes: 5

RandomGuy
RandomGuy

Reputation: 338

require 'facebook.php';

$app_id = "your app id";
$app_secret = "your app secret";
$facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => true,
));

$signed_request = $facebook->getSignedRequest();


$like_status = $signed_request["app"]["liked"];


if ($like_status == 1){
echo 'User likes this page';
}
else{
echo 'User doesn\'t like this page';
}

Maybe you should try somethng like this, check Facebook's PHP SDK reference page for the exact approach.

Upvotes: 1

Related Questions