• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • About
  • Projects
    • GStaticMap WP Plugin
  • Contact
  • Privacy Policy

Lorenz Blog

All About Web & Mobile Application Development

  • Featured Articles
  • Gadgets
    • Android
    • Blackberry
  • Programming
    • Android
    • PHP
    • Java Script
    • MySQL
    • Postgresql
    • Flex
    • Web
  • Software
    • Mac OS
    • Windows
    • Linux
  • Web
You are Here » Home >> Information Technology >> Programming >> PHP >> How to Create Facebook Application with PHP for Beginner

How to Create Facebook Application with PHP for Beginner

December 5, 2009 by Lorensius Londa 28 Comments

Facebook is the fastest growing social networking application that currently has more than 350 million active users. One of it’s key features is Facebook Platform, that enable us to build  applications on Facebook. Currently there are a lot of Facebook  applications built by developers around the world such as game, which is the most popular application on Facebook.

This tutorial will guide you through the creation of a Facebook application using Facebook PHP API that will display Hello World text, called Hola Mundo.  Before we begin to create Facebook application, there are a few things that you have to know:

  • You should be familiar with PHP  programming language
  • You need to be familiar with web hosting fundamentals and have a place to deploy your application
  • You must have a Facebook account

If you have meet the requirements above, you are ready to get started  building Facebook application through this tutorial.

A. Setting Up Your Application

  • Go to Facebook developers area, and click Set Up New Application button
Facebook Developers Area
Facebook Developers Area
  • Type the application name (Hola  Mundo), choose Agree on Facebook Term and then click Create Application button
Create New Application
Create New Application
  • Then Facebook will create two keys for your application, the API key and the secret key, write them and save on a file for later use.
Setup Application
Setup Application
  • Go to Canvas tab and type a unique URL for your application (hollamundo) on Canvas Page URL, it must be unique or you’ll  get error message if the URL has been used by another application.  In this case i use hollamundo rather than holamundo because it has been used by another application. On Canvas Callback URL, type the URL for the application page on your server . Choose FBML On Render Method option under Canvas Settings,  which enables you to build full Facebook Platform applications that deeply integrate into a user’s Facebook experience. Let another setting options to it’s default then click Save Changes button.
Canvas Settings
Canvas Settings
  • At this time your application is ready, try to type your Canvas Page URL on browser and see what the results. What you get is an error message because your application doesn’t exists on your server, ok don’t worry, lets go to next steps.

B. Configure Application on Your Host

After configuring your application on Facebook, it’s time to do a little bit coding and some server administration tasks.

  • Download Facebook  Client Library and extract it, you will find two directories inside,  footprints and php. Copy all files from php directory and upload them to your facebook application directory on your server, that must be the same with Canvas Callback URL you set before.
  • Create index.php file with the following contents:
<?php
include_once 'facebook.php';

$apikey    = 'typeyourapikeyhere';
$secretkey = 'typeyoursecretkeyhere';

$fbObj     = new Facebook($apikey, $secretkey);

$myuid     = $fbObj->require_login();

$fbml      = "<h2>Hello world, my name is <fb:name uid=\"$myuid\" useyou=\"false\" />,"
           . "welcome to my first facebook application!</h2>";
echo $fbml;
?>

Simple right ? Facebook has made it simple using FBML, all you have to do is apply the predifined tags on your code. You can read the complete explanation about FBML on Facebook Developers Wiki page here .

line 2:  include the facebook main library file

line 4&5:  define your api key and secret key

line 7:  create an instance of Facebook client class

line 8:  get your facebook user id (uid), the require_login method is used to force user to logged into Facebook before using the application. If they are not logged in, Facebook will redirect them to Facebook login page first and then brings them to your application page after they logged in.

line 9:  your page content’s that display your name using FBML Fb:name tag.

Now your application is complete and ready to be accessed by anyone in the world. Type your Canvas Page URL on browser and you’ll get Allow Access page which is default for Facebook application for the first time access, click Allow button to access your application.

Allow Access Page
Allow Access Page
Your Application Page
Your Application Page

You can view live example application above here

Facebooktwitterredditpinterestlinkedinmailby feather

Related posts:

  1. How to Enable Facebook Like Button on a Web Page Using AddThis
  2. How to Delete Preinstalled Android Application
  3. How to Use Foursquare API on Android Application
  4. How to Use Flowplayer as Your Web Video Player (Beginner’s Guide)

Filed Under: Featured Articles, Information Technology, PHP, Programming Tagged With: facebook, facebook application beginner, facebook application howto, facebook application php, facebook application tutorial, facebook tutorial beginner, fbml, PHP

About Lorensius Londa

Passionate web and mobile application developer. Co-founder of TRUSTUDIO, loves programming, Android, aviation, travelling, photography, coffee and gym mania.

Reader Interactions

Comments

  1. Colin Brady says

    January 29, 2010 at 12:08 am

    Hi,

    Great tutorial, however I did not work for me.

    I created a directory in my website http://www.trendspot.ie.

    I called it ‘facebook’.

    I created the index.php file and dragged it into the my new ‘facebook’ directory along with the the php files in the facebook client library. I did this using FTP.

    When I go to preview the app I get this message…
    Not Found
    The requested URL /facebook/ was not found on this server.

    Apache/1.3.37 Server at trendspot.ie Port 80

    I don’t know what I’m doing wrong and I hope you could help!

    Thanks,

    Colin

    Reply
    • lorenz says

      January 29, 2010 at 7:41 pm

      Hi Colin,

      Have you tried to directly access the ‘http://www.trendspot.ie/facebook’ ? was it work ?

      Reply
    • Martin K- says

      December 10, 2013 at 6:10 pm

      It needs to be “https” page at your web server, Facebook don’t let you use http

      Reply
  2. Hass says

    May 12, 2010 at 9:29 am

    hi lorenz

    i’m now stuck at the canvas callback url
    i understand that i can’t use localhost for my application and neither do i have a webhost. I saw that you use some ip address for the callback url. can you help me with these cuase i think that is my main problem to display my application on facebook..help me please.
    thank u so much

    Reply
  3. Ganybhat says

    June 18, 2010 at 7:55 pm

    Very nice tutorial!. Thank you very much.

    Reply
  4. Rahul Anand says

    June 19, 2010 at 3:21 am

    Hello,
    Nice tutorial. Like that. I am facing 1 problem now. Redirection Problem. When I hit the Url of my app then it start infinite redirection url. I think the token is not getting verified. Please let me know how can I resolve this??

    Thanks
    Rahul Anand

    Reply
  5. Rahul Anand says

    June 19, 2010 at 3:22 am

    Please reply me on my Email ID.

    thanks

    Reply
  6. Lux says

    June 30, 2010 at 12:39 pm

    Quick question, it looks like I could just add the rest of my php script under the code facebook provides, so in other words if i had a stand alone php script I could easly turn it into a facebook app. I this right what I am understanding?

    Reply
  7. Book of Ra says

    April 18, 2011 at 9:13 pm

    Hey…This sounds verry good. Amazing Novoline and Book of Ra options. I will try it as sonn as possible..:Thank you sir 🙂

    Reply
  8. Bookofradeluxe says

    June 20, 2011 at 9:46 pm

    Book of Ra, Sizzling Hot und viele andere bekannte Slots stammen vom Hersteller Novoline

    Reply
  9. Mr. Facebook says

    July 13, 2011 at 5:42 pm

    Go to http://www.7tech.co.in/php/how-to-create-a-facebook-application-using-php/ to learn more about the facebook application development. 😉

    Reply
  10. U Tanna says

    September 21, 2011 at 7:21 pm

    Hello,

    I am facing some unique problem in fb app.
    Recently we have shifted our fb app to another server
    We have installed lamp server on new server and copied all files in that new server, keeping all root directories and folder positions to be same and also changed all pointing to new servers.

    But when we tried to open app it is showing us “Failed to load source for: http://xxx.xxx.xx.xxx/xyz/?auth_token=f02eec916d6895d7ff65”

    Please help

    Reply
  11. www.thetrick.in says

    October 13, 2011 at 3:09 pm

    thanxxx….

    Reply
  12. Nick Lachey says

    January 4, 2012 at 7:22 pm

    Nice post. I found this blog which provides you how to create any type of business application and easily integrate it into your Facebook business page
    http://blog.caspio.com/integration/create-a-custom-facebook-application-for-your-business/

    Reply
  13. Le hai says

    March 29, 2012 at 11:58 pm

    great post . Thanks you so much

    Reply
  14. novoline says

    May 8, 2012 at 4:12 pm

    Bookofradeluxe
    June 20, 2011 at 9:46 pm

    Book of Ra, Sizzling Hot und viele andere bekannte Slots stammen vom Hersteller Novoline

    Reply
  15. Webmaster says

    November 18, 2012 at 4:44 pm

    Thank you for this guide. We will insert this facebook login on our rating and review site. It works already on our test-site. The only thing we could not manage is to replace the text “login with facebook” with the login button of facebook. Any idea how to solve that problem? Thank you.

    Reply
  16. Joby Joseph says

    February 10, 2012 at 2:47 am

    How To Create a Facebook Application http://bit.ly/AdW6zl

    A very simple how to guide for beginners.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About Me

A husband, father of two, passionate software developer, diy lover and home baker who loves to learn new things. Read More…

  • Facebook
  • GitHub
  • Google+
  • Instagram
  • Twitter
  • YouTube

Featured Articles

How to Setup MQTT Server Using Mosquitto and Libwebsocket on Freebsd

Blue Bamboo P25 Printer Android Demo Application With Source Code

Simple JSON RPC Client for Android

How to Send Message to Google Cloud Messaging (GCM) Server Using JSON and PHP

Footer

Recent Comments

  • Aditya Dabas on About
  • Ayten Göksenin Barutçu on How to Make Android Map Scrollable Inside a ScrollView Layout
  • mang jojot on About
  • Hussain on How to Programmatically Scan or Discover Android Bluetooth Devices

Recent Posts

  • How to Fix Blank Screen on WordPress Add/Edit Post Page
  • How to Programmatically Restart the ESP32 Board
  • How to Get Hardware Info of ESP32
  • How to Setup MQTT Server Using Mosquitto and Libwebsocket on Freebsd

Latest Tweets

  • @tricahyono_bowo @infobandung @infobdg Wah kejauhan om 355 days ago
  • Wilujeng enjing sadayana..Mohon info tempat powder coating dan sandblasting yg recommended di Bandung dunk @infobandung @infobdg359 days ago

Copyright © 2023 · Magazine Pro on Genesis Framework · WordPress · Log in