Search code examples
phpfacebookfacebook-graph-apifacebook-likefacebook-page

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.


Solution

  • <?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