栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

检查用户是否喜欢页面的无缝方式

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

检查用户是否喜欢页面的无缝方式

当然可以!如文档中所述,Facebook将在以下位置向您发送一些其他详细信息

signed_request

当用户导航到Facebook页面时,他们将在下一个可用的标签位置看到您的“页面标签”。大致而言,页面选项卡的加载方式与画布页面完全相同。当用户选择“页面选项卡”时,您将收到带有另一个附加参数page的signed_request参数。此参数包含一个JSON对象,其ID为ID(当前页面的页面ID),admin(如果用户是该页面的管理员)和被喜欢(如果用户喜欢该页面)。与“画布页面”一样,在用户授权您的应用之前,您将不会在signed_request中收到您的应用可访问的所有用户信息。

从获取的代码应类似于:

<?phpif(empty($_REQUEST["signed_request"])) {    // no signed request where found which means    // 1- this page was not accessed through a Facebook page tab    // 2- a redirection was made, so the request is lost    echo "signed_request was not found!";} else {    $app_secret = "APP_SECRET";    $data = parse_signed_request($_REQUEST["signed_request"], $app_secret);    if (empty($data["page"]["liked"])) {        echo "You are not a fan!";    } else {        echo "Welcome back fan!";    }}function parse_signed_request($signed_request, $secret) {    list($enpred_sig, $payload) = explode('.', $signed_request, 2);    // depre the data    $sig = base64_url_depre($enpred_sig);    $data = json_depre(base64_url_depre($payload), true);    if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {        error_log('Unknown algorithm. Expected HMAC-SHA256');        return null;    }    // check sig    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);    if ($sig !== $expected_sig) {        error_log('Bad Signed JSON signature!');        return null;    }    return $data;}function base64_url_depre($input) {    return base64_depre(strtr($input, '-_', '+/'));}?>

更新的代码: 虽然以前的代码可以工作。我没有_检查_请求的有效性。这意味着有人可以篡改请求并向您发送虚假信息(例如将设置

admin
true
)。代码已按照
signed_request
文档编制方法进行了更新。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/442986.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号