本文介绍了如何使用php/javascript检查用户是否喜欢该页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想已经有很多人问过这个问题,但是我仍然需要一个解决方案来检查登录用户是否喜欢该页面.我尝试了很多解决方案,但没有一个主题在起作用.
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.
我尝试使用以下代码
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 instruct 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...";
}
这篇关于如何使用php/javascript检查用户是否喜欢该页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!