Create a page tab to its Facebook page (without FBML)

Things are moving fast on Facebook , in particular regarding the API and tools available to developers . Thus, FBML will soon disappear in favor of 100% iFrame applications which will also impact the most personalized page tabs that are themselves derived from application. So, the theory and practice moving in the establishment of a tab to the facebook page of your business or your website. The good news is that it is now much more efficient and - most importantly - identical to the traditional web programming, almost.

Before anything else, little reminder about how to have its own tab page . It seems there are many apps for automatic generate a page tab but it is never better served than by either yourself. For the record, all Facebook applications and tabs arising are hosted by the developers themselves and not by Facebook. It goes without saying , therefore , that anything that follows assumes that you have a dedicated hosting it . ( a / facebook / on the site that will be a page will do nicely ) . Note however have PHP5 .Create a page tabA tab page is necessarily generated by an application. The first thing to do is to create an application if you want to have a good tab to you. Even if the application is useless other than that. To create an application (and therefore have a tab available ) is simple just go here: http://developers.facebook.com/setup/ . Once created you can go to change the settings for fill in at least these:" Facebook Integration " tab > Page canvasPermalink to your application ( free choice )Tab " Facebook Integration "> URL template (eg http://www.sitedemonentreprise.fr/facebook/ )Absolute URL that Facebook will load into the iframe called by the permalink of your application ( see above " canvas page ")Tab " Facebook Integration "> URL tabRelative URL ( relative to your canvas URL ) that Facebook will load into the iframe called tab page generated by your application ( tab / or http://www.sitedemonentreprise.fr/facebook/onglet/ )Once completed these appointments on the " profile page of your application " ( link on the home page of your application settings , make to get to the same place the secret key and the id of your application that will be useful early or later . )A tab page is what?A tab is composed of at least one "index" which will be called by Facebook to load the page that is displayed tab page itself . If you want to display on this tab navigation to provide different content to your "fans" you have the opportunity to do so via a traditional navigation and relative links ( for external links , eg to your website , do not forget add target = " _parent " to your tag) . In this case the "tab" your facebook dedicated hosting directory will contain several pages: index.php actus.php , videos.php etc ...Within each script / page you can include style sheets and javascript but you can not call remote scripts or load greater than a few kilobytes scripts. So we forget jQuery or other FrameWork and simple content and CSS properties are preferred to the same file.Fan vs Fan Not ?Recently, Facebook returns the $ _REQUEST [ signed_request ] every time you call a page on Facebook, in the decoding it is possible to know if the person is a fan of your page or not . Convenient to display all or part of your content depending on the status of your drive. Go here for more information on this variable : http://developers.facebook.com/docs/authentication/signed_request/For what interests us , the script below will allow you to load the first display different content to fans and others:


$signed_request = $_REQUEST['signed_request'];
$secret = 'clesecretedevotreapplication';

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, '-_', '+/'));
}
$decoded_signed_request = array();
$decoded_signed_request = parse_signed_request($signed_request,$secret);
if($decoded_signed_request['page']['liked']){
//contenu fan
include ('fan.php');
}
else{
//contenu pas fan
include ('pasfan.php');
}






Note that the variable signed_request also provides information on the admin status ($ decoded_signed_request [ 'page' ] [' admin'] ) or not the visitor which opens interesting perspectives to display additional options to the directors of the page only ...

Post a Comment

0 Comments