For Sales Enquiry, call: +91 789 216 9998 For HR Enquiry, call: +91 804 166 0003 Skype: globussoftsupport

Progressing towards Innovation...


Developing Facebook Application Using Facebook Graph API in PHP - Globussoft

August 4, 2014by GLBADMIN12

Hi, I am Ramanjineyulu. I, along with my colleague Abhinish Kumar, worked on developing Facebook application using facebook Graph API (in PHP) recently. This Application helps retrieve the all public details of a user and displays it in a useful format. We found this very interesting and want to share in easy steps how we went about it.

What is Facebook Application?

Facebook Applications are developed to enhance one’s experience on Facebook. It is provided by the social networking giant Facebook for third-party developers to create their own applications and services that access Facebook data.

Facebook provides SDK for development of Facebook Applications in various platforms like PHP, iOS etc. Facebook SDK for PHP is provided by Facebook for Application development in PHP. Facebook keeps updating its SDKs and it is recommended to use the latest one.

Graph API

The Graph API is the core of Facebook Platform, enabling developers to read from and write data into Facebook. The Graph API presents a simple, consistent view of the Facebook social graph, uniformly representing objects in the graph (e.g., people, photos, events, and pages) and the connections between them (e.g., friend relationships, shared content, and photo tags).

Getting Started

After logging in to Facebook with your valid credentials, you need to create your own application to enhance your experience on Facebook. For this you need to follow the following steps:


Go to developer page, here you can choose Apps tab and then click on ‘Create new App’. After that follow the instructions and give the valid name and namespace for that App. Here are the sub-steps:

• Visit Facebook’s Developer Site (you need a Facebook verified account to create the application)

• In the ‘docs’ section you can find various SDKs, download the SDK for PHP. You will get the SDK as a zip file, extract it to any location. In the SRC folder, you will get a Facebook folder containing the library files; copy the entire Facebook folder into the root of your application.


•     Include the various files you need for your application

•     Create an application on Facebook and note your App ID and App Secret, you will need them while creating your application, provide other details as necessary.



•    Go to settings and provide the settings you need for your app. You are now ready to start developing your Facebook Application.

Developing the Application

First you need to configure all those files which are required to develop the Application. Next you can follow these steps:
•    You will need to have configured a Facebook App, which you can obtain from the App Dashboard.

•    Now initialize the SDK with your app ID and secret:

•    The SDK can be used to support login to your site using a Facebook account. On the server-side, the SDK provides helper classes for the most common scenarios.

•    For your website you can use the FacebookRedirectLoginHelper. Generate the login URL to redirect visitors to with the getLoginUrl();  method, redirect them, and then process the response from Facebook with the getSessionFromRedirect();  method, which returns a FacebookSession.
$helper= new FacebookRedirectLoginHelper(‘your redirect Url’);
$loginUrl= $helper->getLoginUrl();

•     Now you have to set the URL for getting response to your Facebook Application. Remember, we already created this earlier. Get this by going to your application -> Settings -> Advanced tab-> valid OAuth Redirect URls -> type your redirect url here.


•     Once you have a FacebookSession you can begin making calls to the Graph API with FacebookRequest.
$request=(newFacebookRequest ($session, ‘GET’, ‘/me’))->execute()->getGraphObject();
Now you have the $request as a GraphObject. By Accessing it you can get the various details of user.

Sample WebApplication in PHP to Get Details

* Description : This application will helps you to get the all public details of user
* first we should include all required files provided by Facebook SDK
include 'Facebook/FacebookCurlHttpClient.php';
include 'Facebook/FacebookRedirectLoginHelper.php';
require_once( 'Facebook/FacebookRequest.php' );
require_once( 'Facebook/FacebookResponse.php' );
require_once( 'Facebook/FacebookSDKException.php' );
require_once( 'Facebook/FacebookRequestException.php' );
require_once( 'Facebook/FacebookAuthorizationException.php' );
require_once( 'Facebook/GraphObject.php' );
require_once( 'Facebook/GraphUser.php' );
use Facebook\FacebookRequest;
use Facebook\FacebookRequestException;
include 'Facebook/FacebookSession.php';
Use Facebook\FacebookSession;
Use Facebook\FacebookRedirectLoginHelper;
* here you have to provide your application ID and SECRET
* which are given by facebook after creating the application
FacebookSession::setDefaultApplication('255253844664429', '5b1644e8f084191cb1bbb2d41c7d73f3');
$helper = new FacebookRedirectLoginHelper('');
$session = $helper->getSessionFromRedirect();
echo "<title>FBApp-Details</title>";
* Code to get the public details of user
if ($session != NULL) {
try {
$user_profile = (new FacebookRequest(
$session, 'GET', '/me'
echo "</br>";
echo "Name : " . $user_profile->getProperty('name') . "</br>";
echo "Email : " . $user_profile->getProperty('email') . "</br>";
echo "Gender : " . $user_profile->getProperty('gender') . "</br>";
echo "Bio : " . $user_profile->getProperty('bio') . "</br>";
echo "Date of Birth : " . $user_profile->getProperty('birthday') . "</br>";
} catch (FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
else {
echo '<a href="' . $helper->getLoginUrl(array(
'scope' => 'user_likes,publish_actions,read_friendlists,email,user_birthday,user_location,
user_about_me,user_friends,user_photos')) . '"><font size="6"><i><strong>
Get Details</strong></i></font></a>';

So you see how interesting it is to develop a web application that interacts with Facebook and gets you the public details of the user.

Similarly, we can develop web applications like post a story on user’s wall, upload photos, tag pics with his friends list, get the user liked pages etc. by using Facebook Graph API in PHP.

Hope you found this interesting too. Keep watching the space for more!



  • Stephenver

    November 30, 2020 at 9:43 pm

    best over the counter viagra viagra non prescription viagra


  • snus

    July 15, 2022 at 4:46 pm

    800894 906886Wonderful paintings! That is the kind of info that are meant to be shared around the web. 58809


  • หนังใหม่

    August 11, 2022 at 5:51 pm

    75276 688509What web host are you the use of? Can I get affiliate link for your host? I wish web site loaded up as quickly as yours lol 101619


  • ytconvert

    August 29, 2022 at 5:05 pm

    634249 915899bless you with regard to the certain weblog post ive really been searching regarding this kind of information on the internet for sum time appropriate now as a result cheers 711476


  • sbo

    August 31, 2022 at 5:22 am

    914462 340569Wow, superb weblog structure! How long have you been blogging for? you make blogging glance easy. The total appear of your internet web site is superb, neatly as the content material! 788576


  • sbo

    September 2, 2022 at 12:36 am

    492707 806820Id ought to talk to you here. Which is not some thing Which i do! I like reading an article that can make men and women believe. Also, thank you for permitting me to comment! 481845


  • benelli vinci

    September 8, 2022 at 6:25 pm

    343433 886112You Finally want the respect off your family and buddies? 397095


  • Firearms For Sale

    September 19, 2022 at 10:13 am

    774238 787824Some times its a pain inside the ass to read what folks wrote but this web website is quite user friendly ! . 533984


  • stoeger gun

    September 29, 2022 at 9:20 pm

    168994 686990Attractive part of content material. I just stumbled upon your internet site and in accession capital to claim that I acquire in fact enjoyed account your weblog posts. Any way Ill be subscribing to your feeds and even I achievement you get entry to constantly speedily. 651031


Leave a Reply

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

Social Networks

Copyright © 2006-2020 Globussoft Technologies