Facebook Application Tutorial Part 2
July 24th, 2010  |  Tutorial

Setting up all together!

Our index.php is our main object in registering to facebook API, calling library and designing our facebook app, first let’s call all initial library and let see how simple to login to facebook API to check users profile in the facebook.

First part of Index.php

<?php
// facebook API library
 include_once ("php/facebook.php");
// this defines some of your basic setup
>include_once ("config.php");
 // this defines some of basic databaswe transaction
>include_once ("actionlib.php");
//include_once ("transactionlib.php");

 // Create the object containing API Client
 $facebook = new Facebook($api_key, $secret);
 // application css
 include_once ("css/stylecss.php");

include_once ("js/halalanscript.php");
// friend status
>include_once ("friendsvote.php");
// Shows standard "allow application" dialog,
// if user has not authorized
 $user_id = $facebook->require_login();
$userdetails = $facebook->api_client->users_getInfo($user_id,
'name,pic_square,profile_url,birthday_date,sex,hometown_location');
?>
$user_id = $facebook->require_login();

here we check if the users of our application is already login to the facebook if not facebook will automatically ask him to login and it will going to return our user facebook Id.

 $userdetails = $facebook->api_client->users_getInfo($user_id,
'name,pic_square,profile_url,birthday_date,sex,hometown_location');

Here is our User details query to facebook we can do it by using fbquery or just use the available facebook API, as you can see we want to get users name, pic_square for user thumb image, profile url, birthday, gender and hometown location.

Second part of Index.php

<?php
$username     = '';
$userlocation = '';
$usercity     = '';
$usergender   = '';
$userbirthday = '';
$username     = $userdetails[0]['name'];
$userlocation = $userdetails[0]['hometown_location']['country'];
$usercity     = $userdetails[0]['hometown_location']['city'];
$usergender   = $userdetails[0]['sex'];
$userbirthday = $userdetails[0]['birthday_date'];
$userstatus = check_userid($user_id);
$uservoted = 0;
?>

At this line of codes we just basically put user details in our variable for processing in our application.

$userstatus = check_userid($user_id);

is our function that can be found in actionlib.php to verify and check if users is already use the application or already in our record.

Related Topic