McM
mcm@noway.es
Contact me: noway.es
Contact me

Facebook application

Here you can find the facebook application I developed for http://wwww.entrenatech.com:

http://apps.facebook.com/vida_saludable/

First of all you must have a quick read to this http://developers.facebook.com/get_started.php.

Then you must configure your application from this site:
http://www.facebook.com/developers/

When you click on "set up your application", several information will be request and finally you will get the api key and the api application secret:

  • Your API key: this key identifies your application to Facebook. You pass it with all your API calls.
  • Your application secret: Facebook uses this key to authenticate the requests you make. As you can tell by its name, you should never share this key with anyone.

These keys are neccesary to develop your server application.

Things to take into account:

  • Maximum Include File Size

    The cacheing wasn't working for us. We used firebug and realized the call to the cached file was returning a 500 error. We read the response and learned that the included file size must be less then 64kb! Im not sure if this applies to included css though.

  • Don't use Relative URL's

    It seems like you must use absolute URL's otherwise an error message is returned. 587721567 12:07, 4 May 2008 (PDT)

    Important Note: Your application will run faster and more reliably if you DO NOT use the URL of your server, but rather, use your server's IP address (if your server has a fixed IP address).

  • Versioning style sheets!

    It is important to change the version of the style sheets when you make changes, otherwise facebook will not consider the last changes you make. For example:

Pieces of code

Canvas URL: You must place in this url the index.php. In the header of the php files you locate in the serv

It is my understanding that this problem can be caused by too many concurrent connections. If you do a

/etc/init.d/sshd restarter you can include this headers:

<?php

// the facebook client library
include_once '../client/facebook.php';

// some basic library functions
include_once 'lib.php';

// this defines some of your basic setup
include_once 'config.php';



?>

You can use the facebook php client that you can download from: http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platf...

and place the client libraries somewhere, in my case:

'../client/facebook.php'

In lib.php you will find some libraries to connect to the database,

<?php

function get_db_conn() {
  $conn = mysql_connect($GLOBALS['db_ip'], $GLOBALS['db_user'], $GLOBALS['db_pass']);
  mysql_select_db($GLOBALS['db_name'], $conn);
  return $conn;
}

function get_prints($user) {
  $conn = get_db_conn();
  $res = mysql_query('SELECT `from`, `to`, `time` FROM footprints WHERE `to`=' . $user . ' ORDER BY `time` DESC', $conn);
  $prints = array();
  while ($row = mysql_fetch_assoc($res)) {
    $prints[] = $row;
  }
  return $prints;
}

function render_profile_action($id, $num) {
  return '<fb:profile-action url="http://apps.facebook.com/footprints/?to=' . $id . '">'
       .   '<fb:name uid="' . $id . '" firstnameonly="true" capitalize="true"/> '
       .   'has been stepped on ' . $num . ' times.'
       . '</fb:profile-action>';
}

...

Config.php has all the parameters to set up the facebook application:
api_key
secret

You can get then from the developer facebook web page as I mention before.
You can also include here some bbdd parameters if you want.

<?php

// Get these from http://developers.facebook.com
$api_key = 'XXXXXXXXXXXXXXXXXXXXXXXX';
$secret  = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
/* While you're there, you'll also want to set up your callback url to the url
* of the directory that contains Footprints' index.php, and you can set the
* framed page URL to whatever you want.  You should also swap the references
* in the code from http://apps.facebook.com/footprints/ to your framed page URL. */

// The IP address of your database
$db_ip = '127.0.0.1';          

$db_user = 'johcaxhi_pruebas';
$db_pass = 'pruebas';

// the name of the database that you create for footprints.
$db_name = 'johcaxhi_pruebas';

$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
$user = $facebook->require_login();

if (isset($_POST['to'])) {
  $prints_id = (int)$_POST['to'];
  $prints = do_step($user, $prints_id);
} else {
  if (isset($_GET['to'])) {
    $prints_id = (int)$_GET['to'];
  } else {
    $prints_id = $user;
  }
  $prints = get_prints($prints_id);
}

/* create this table on the database:
CREATE TABLE `footprints` (
  `from` int(11) NOT NULL default '0',
  `to` int(11) NOT NULL default '0',
  `time` int(11) NOT NULL default '0',
  KEY `from` (`from`),
  KEY `to` (`to`)
)*/

facebook.php: In this file you will find the api to access to the facebok libraries.

coming next ... code snippets...

Share it!

Twitter Gmail Delicious Google Bookmarks Hotmail Yahoo Mail Share/Bookmark