Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Created August 18, 2014 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save niraj-shah/c582890e03c19b41ec7b to your computer and use it in GitHub Desktop.
Save niraj-shah/c582890e03c19b41ec7b to your computer and use it in GitHub Desktop.
Checking if a user has liked a specific page using Facebook PHP SDK 4.0.x and Graph API 2.0+
<?php
// get like status
$liked = (new FacebookRequest( $session, 'GET', '/me/likes/' . $page_id ))->execute()->getGraphObject()->asArray();
// if $liked return array with at least one result, user has liked the page
if ( isset( $liked ) && count( $liked ) > 0 ) {
echo '<h2>Liked</h2>';
} else {
echo '<h2>Not Liked</h2>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment