0

How do I check if a user who is logged in to my website via the facebook php sdk has liked my page so that I can show him some secret content...

Deval Khandelwal
  • 3,458
  • 1
  • 27
  • 38

2 Answers2

1

If you have the appropriate permissions you can access the Likes property of the user: you can then check the returned list to see if your URL is in the list. You can use something like this:

$likes = Facebook::api('/me/likes','GET');
Femi
  • 64,273
  • 8
  • 118
  • 148
0

Here is another approach using check if $signed_request->page->liked:

function parsePageSignedRequest() {
    if (isset($_REQUEST['signed_request'])) {
      $encoded_sig = null;
      $payload = null;
      list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
      $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
      $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
      return $data;
    }
    return false;
  }
  if($signed_request = parsePageSignedRequest()) {
    if($signed_request->page->liked) {
      echo "This content is for Fans only!";
    } else {
      echo "Please click on the Like button to view this tab!";
    }
  }

Detail Here>>

Vijaya Pandey
  • 4,252
  • 5
  • 32
  • 57