我想知道用户是否喜欢我的粉丝页面(我在里面安装了一个 FB 应用程序作为标签)页面,
我在网上搜索并找到了这个应该可以工作的代码:
$signed_request = $facebook->getSignedRequest();
echo "<pre>";
print_r($signed_request);
echo "</pre>";
$liked = $signed_request["page"]["liked"];
这是我得到的数据,但我不知道用户是否喜欢这个页面:
大批
(
[algorithm] => HMAC-SHA256
[code] => AQA7PQo8FBLaHlEe3IgYMBg_4Smwt_qsgWpiUnnG2XIco0ndK3zcCMgK4M7975cr1oUmL2iYv5UhBKM-hAxOmUUwbhuj2ZHfMiLNeO8ZBc4c5jexI-VZuDGFwnnW4-eg433gVbDo_uLQ8MBpjI2kT8c6B_VvNLoY4_Oel5odc6tObW54a0Thdd7a_Bhq-kHOHz-CJxgBOWLDGR9plUhgZGs9o34jHfOZLFRGOQvSxd1PcFkuMorKy2lP9AHnBdZ2BI8wsy_U_TGbPPt2uGdS5nkpvJbfvh5JPT8zULAm_nWBtZ4YfZcngSj64KZDvr8Fwr0
[issued_at] => 1374161190
[user_id] => ----
)
我错过了什么?
谢谢
最佳答案
捕获已签名的请求后,您需要执行三个步骤:
.
字符(例如 238fsdfsd.oijdoifjsidf899
)划定的两部分。 这是一个完成所有这些工作的函数:
$signed_request = $_REQUEST['signed_request'];
function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$sig = null;
$payload = null;
list($sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}
用法:
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {
echo "User liked the page";
}
else {
echo "User haven't liked your page (yet)";
}
}
文档: Signed Requests 、
base64_decode()
、 json_decode()
关于php - FB PHP SDK 知道用户是否喜欢我的标签页,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17728031/