Posted By

erikportin on 05/26/11


Tagged

php facebook


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Malm
Komsomol


Check if user liked page | PHP | Facebook


 / Published in: PHP
 

  1. <?php
  2. $session = $facebook->getSession();
  3.  
  4. $user = $facebook->getUser();
  5. $page = 'PAGEID';
  6.  
  7. // Session based API call.
  8. if ($session) {
  9. try {
  10. $likeID = $facebook->api(array( 'method' => 'fql.query', 'query' =>
  11. 'SELECT target_id FROM connection WHERE source_id =' . $user . 'AND target_id =' .$page ));
  12.  
  13. if ( empty($likeID) ) {
  14. // user has NOT Liked the page
  15. echo "Like my page!";
  16.  
  17. } else {
  18.  
  19. // user HAS Liked the page
  20. echo "Thank you for liking my page";
  21.  
  22. }
  23. } catch (FacebookApiException $e) {
  24. error_log($e);
  25. }
  26. }
  27. ?>

Report this snippet  

You need to login to post a comment.