开发者

How to check whether user has liked the page or not using php/javascript [duplicate]

开发者 https://www.devze.com 2023-04-03 20:37 出处:网络
This question already has an answer here: Closed 11 years ago. Possible Duplicate: Seamless way to check if user likes page
This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

Seamless way to check if user likes page

I think so many people have been asked this quesion,But still I need a solution to check whether logined user has liked the page or not.I have tried so many solutions but none of theme were working.

I have tried with the following code

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!";
  }
}

I could not get the user "liked" response. So any can instruc开发者_JAVA技巧t me how what should I do to get the user "liked" response.


function parse_signed_request($signed_request, $secret) 
{
  list($encoded_sig, $payload) = explode('.', $signed_request, 2);

  // decode the data
  $sig = base64_url_decode($encoded_sig);
  $data = json_decode(base64_url_decode($payload), true);

  if(strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
    $error['signed_request'] = 'Unknown algorithm. Expected HMAC-SHA256';
    return null;
  }

  // check sig
  $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
  if($sig !== $expected_sig) {
    $error['bad_signed_json'] = 'Bad Signed JSON signature!';
    return null;
  }

  return $data;
}

function base64_url_decode($input) {
  return base64_decode(strtr($input, '-_', '+/'));
} 

$signed_request_data = parse_signed_request($_REQUEST['signed_request'],$fb_app_secret);

if($signed_request_data['page']['liked']) {
  print "Content for Useres who have liked your page...";
}


I think you'll have to use FQL, and specifically query the page_fan table.
Do read the FB documentation that i have mentioned in the above links. Further to build such FQL queries you can visit this linked answer.
Thats all i can tell now, hopefully it helps!
Edit:
@MuckyBuzzwoo's answer will also work for page tabs, the signed_request has a liked field $data['page']['liked'] that shows if the currently visiting user to the tab has liked the page or not.

0

精彩评论

暂无评论...
验证码 换一张
取 消