how to find user likes facebook page like

If you want to know how to find user likes facebook page like your page or not. After few experiments i found this working code that i want to share with you.

$FB_PAGE_ID = ''; //assign facebook page id.
$facebook = new Facebook(array(
  'appId'  => APP_ID,
  'secret' => SEC_KEY,
  'cookie' => true,
));
$user = $facebook->getUser();
if ($user) {
  try {
       $likes = $facebook->api("/me/likes/".$FB_PAGE_ID);
       if( !empty($likes['data']) ) $page_liked = true;
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}
if($page_liked) {
  echo "user likes page";
} else {
  echo "user dont likes page";
}
Share this nice post: