Facebook edge.create [英] Facebook edge.create

查看:68
本文介绍了Facebook edge.create的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了edge.create事件,该事件也可以由浏览器触发.但是,当他们回到网站时,如何检查用户是否喜欢该页面呢?

I have added the edge.create event and the event can be fired by the browser as well. But how can I check if the user has liked the page when they come back to the site?

<div id="fb-root"></div>
<script type="text/javascript">
<!--
window.fbAsyncInit = function() {
 FB.init({appId: 'YOUR_FACEBOOK_APP_ID', status: true, cookie: true, xfbml: true});
 FB.Event.subscribe('edge.create', function(href, widget) {
 // OK
 });
};

推荐答案

您将要看看签名请求文档 ...

此签名的请求是facebook方法,用于验证发出请求的用户确实是他/她说自己是谁".它被加密并使用您的应用程序密钥对值进行解码.
解析此签名的请求后,您将拥有所需的数据.

You are going to want to take a look at the signed_request documentation...

This signed request is facebooks method of validating that the user that made the request is indeed "who he/she says they are". It is encrypted and and uses your application secret to decode the values.
Once you parse this signed request you will have the data you need.

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_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_decode($input) {
  return base64_decode(strtr($input, '-_', '+/'));
}

这篇关于Facebook edge.create的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆