“Hello Philippines” My First Facebook Application
October 31st, 2009  |  Tutorial

Please note that “Hello Philippines” application is an only a basic example of facebook application, like we always do in some programming language we start our programming by saying “Hello World” output.

Here we will start our development in saying “Hello Philippines” with user picture, some basic information and link to facebook profile.

To start our application development we need to download the following facebook client libraries which is PHP 5.

http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platform.tar.gz

Extract the file to your www folder or to your sub domain root folder sample the “Hello Philippines” folder is on http://www.helloapp.facebookgarage.ph where technically http://www.facebookgarage.ph/helloapp/ – folder

Create config.php and insert this code:

<?php
// Author Aristedes L. Royo
// Copyright 2004-2009 www.facebookgarage.ph. All Rights Reserved.
// Date: Oct 31, 2009
// —————————————————————————-
// | THIS SOFTWARE IS PROVIDED BY THE AUTHOR “AS IS” AND ANY EXPRESS OR      |
// | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
// | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.   |
// | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,          |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT  |
// | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     |
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       |
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  |
// | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.         |
// —————————————————————————--
// You can also use this file handle other settings
// like database and global variable
// API & SECRET KEY

$api_key = ‘YOUR APPLICATION API KEY‘;
$secret = ‘YOU APPLICATION SECRET KEY‘;

?>

Create Index.php file and insert this code:

<?php
// Author Aristedes L. Royo
// Copyright 2004-2009 www.facebookgarage.ph. All Rights Reserved.
// Date: Oct 31, 2009
// —————————————————————————-
// | THIS SOFTWARE IS PROVIDED BY THE AUTHOR “AS IS” AND ANY EXPRESS OR      |
// | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
// | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.   |
// | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,          |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT  |
// | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     |
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       |
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF  |
// | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.         |
// —————————————————————————–
// Facebook API library
include_oncefacebook-platform/php/facebook.php‘;
// This defines some of your basic setup
include_onceconfig.php‘;
// Create the object containing API Client
$facebook = new Facebook($api_key, $secret);
// 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,profile_url’);
//From here we can do everything within facebook app terms and usage
echo<h2> Hello Philippines </h2>“;
echo<img src=’”.$userdetails[0]['pic'].”‘ />“;
echo<br />Name:”.$userdetails[0]['name'];
echo<br /><a href=’”.$userdetails[0]['profile_url'].”‘ >Go to profile</a>“;
echo<br />This is sample application by <a href=\”http://www.facebookgarage.ph\”>www.facebookgarage.ph</a>“;
?>

Or download the complete file here:
http://www.facebookgarage.ph/helloapp/helloapp.zip

View the output of application :
http://apps.facebook.com/hellophilippines/

Related Topic

David at 10:29 am November 3

Nice, clean and basic example thanks for the code

Administrator at 7:26 pm November 4

No problem, overall you can do everything in index.php just take allot of study in FMBL.