开发者

Showing a pop up window when someone likes my fb page

My client wants to display popup window with some coupon codes when some one clicks the like button of his shops facebook fan page. He is currently using the static fbml. I never worked with fb pages before. So know nothing about there api. I prefer javascript if possible. Or for anything else please explain step by step. Thank 开发者_StackOverflowyou in advance.


There is only one way to do this. With a landing page and it checks to see if the page is liked or not. You are going to have to create an application by going to http://developers.facebook.com/apps. Tis will allow you to create a new landing page. You will need a server to host it on or use the free cloud service that they now provide. The app will need to be created with one of the SDK's from https://developers.facebook.com/docs/sdks/. With PHP to check if someone likes the page you use code like

<?php
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;
}
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, '-_', '+/'));
}
if($signed_request = parsePageSignedRequest()) {
if($signed_request->page->liked) {?>
 Page Liked - Display HTML
   <?php } else { ?>
 Dont Like Page - display html
<?php }
}
?>

Now from here you can create any page to display what ever content you pretty much wish.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜