Facebook Application Tutorial Part 1
June 28th, 2010  |  Tutorial

Setting Up our working environment , database design and configuration file.

First we will create a folder for our facebook application since I'm going to use my domain or hosting as my facebook application home. We will create a sub-domain http://halalan.facebookgarage.ph with this it will going to create a folder halalan.

Inside in the halalan folder we will create js folder for our java script files and php folder for our php library downloaded from facebook dev PHP 5 Library, css folder for our cascading style sheet file or css script.

Our application working environment will going to be look like this.

Halalan

  • js
  • php
  • css
  • include

There is now special in this structure we just need to separate some object or some of our application task and work so we can easily modified and find files that we need. We are not really implementing 3 tier architecture here just simple separation of files.

include folder is for other 3rd party files we need to run our applicaton.

Halalan2010 app Database design

Votetally table storage for users vote information.

CREATE TABLE IF NOT EXISTS `votetally` (
  `sysid` bigint(20) NOT NULL auto_increment,
  `fbuserid` bigint(20) NOT NULL,
  `candidateid` int(11) NOT NULL,
  `datevoted` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `remarks` varchar(140) default NULL,
  PRIMARY KEY  (`sysid`),
  KEY `fbuserid` (`fbuserid`,`candidateid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=555 ;

Candidate table predefined candidate information.

CREATE TABLE IF NOT EXISTS `candidate` (
  `sysid` int(11) NOT NULL auto_increment,
  `fullname` varchar(120) NOT NULL,
  `nickname` varchar(30) NOT NULL,
  `picture` varchar(255) NOT NULL,
  `party` varchar(120) NOT NULL,
  `fbprofile` varchar(120) NOT NULL,
  `website` varchar(120) NOT NULL,
  `remarks` varchar(255) default NULL,
  PRIMARY KEY  (`sysid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

Fbusers table storage for facebook users.

CREATE TABLE IF NOT EXISTS `fbusers` (
  `sysid` bigint(20) NOT NULL auto_increment,
  `fbuserid` bigint(20) NOT NULL,
  `name` varchar(120) NOT NULL,
  `location` varchar(140) NOT NULL default 'Philippines',
  `city` varchar(120) NOT NULL default 'Manila',
  `gender` varchar(6) default NULL,
  `birthday` timestamp NULL default NULL,
  `registerdate` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `voted` tinyint(4) NOT NULL default '0',
  PRIMARY KEY  (`sysid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=191 ;

Our configuration file config.php

<?php
$api_key = '8b671357g4993e0b537dffe5779aac68';
$secret  = '8ded2370h70e60c41b61b2eefde8246f';
$baseUrl        = 'http://apps.facebook.com/philippines-election/';
$callbackUrl    = 'http://facebookgarage.ph/halalan/';

$db_ip   = 'localhost';
$db_user = 'MYSQL_USERNAME';
$db_pass = 'MYSQL_PASSWORD';
$db_name = 'APP_DATABASE_NAME';
 ?>

Config.php contains our information that we need to access our application database api key and secret key from facebook api also reside here so any time we need this information we just need to call the config.php files.

$baseUrl is url that we setup during our registration of facebook app to facebook philippines-election is the unique name of our application to different facebook app out there.

$callbackUrl is the exact url of our facebook application location if we create sub-domian http://halalan.facebookgarage.ph and it will going to create a folder halalan the exact url of our application is in http://facebookgarage.ph/halalan

Tags: · · · · ·

Random Posts