4

Many Facebook app ask you "like" it before use it. How to implement it? Is there special API for it?

bkaid
  • 51,465
  • 22
  • 112
  • 128
Gary Li
  • 401
  • 5
  • 12
  • What sort of app are you building? Aka, what programming environment are you using? – Tristan Jun 16 '11 at 02:45
  • The app still is in draft .It is for presenting some product .we haven't decide to use FBML or Iframe . The programming env is PHP . – Gary Li Jun 16 '11 at 03:10
  • possible duplicate of [Seamless way to check if user likes page](http://stackoverflow.com/questions/5329818/seamless-way-to-check-if-user-likes-page) – ifaour Jun 16 '11 at 06:12

2 Answers2

5

FBML pages have been deprecated and you can now only create iframe fan pages. When the user navigates to your page, Facebook sends a signed_request parameter that you will need to decode. This article has a walkthrough on how to do it.

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!";
    }
  }
bkaid
  • 51,465
  • 22
  • 112
  • 128
1

If your app is an iframe loaded in a Page tab signed_request can be used. http://developers.facebook.com/docs/authentication/signed_request/

Kiran Gopakumar
  • 82
  • 1
  • 1
  • 7