Facebook How To

How To Make Facebook App- Beginners Guide

Written by Aman yadav

Making Facebook app help you to earn much more & easy to make for a beginner, but the question is how to make a facebook app. I say making a Facebook app is not so much difficult if you have knowledge of either PHP, ios, android, unity or javascript because these are a different platform in which you can make your app. Now skip extra writing & learn how to make a Facebook app ( By this tutorial beginner also start their app either they are not expert in above mention languages).

 Facebook App tutorial

Different platform for the Facebook app:

  • PHP: This usually normal app making platform by which you can make an app for your own website page, server side app (this mean you can store Facebook data to a server or can take Facebook data from the server), facebook graph API, canvas app. Few Examples of PHP platform app
  • How to Use Facebook API in PHP App.

Facebook Session:

This is a Facebook session which allows you to make a request for Graph API. Validate request by session, Here is session used for:

use Facebook\FacebookSession;
FacebookSession::setDefaultApplication('app-id', 'app-secret');
// If you already have a valid access token:
$session = new FacebookSession('access-token');
// If you're making app-level requests:
$session = FacebookSession::newAppSession();
// To validate the session:
try {
$session->validate();
} catch (FacebookRequestException $ex) {
// Session not valid, Graph API returned an exception with the reason.
echo $ex->getMessage();
} catch (\Exception $ex) {
// Graph API returned info, but it may mismatch the current app or have expired.
echo $ex->getMessage();
}

The above code copy from Facebook developer doc. Let’s have a description on this:-

Few key methods for start session of facebook:

  • SetDefaultApplication: By this set default your Facebook app ID code & App secret code(I hope you know what i am talking about, IF NO CLICK HERE). This information stored in your Facebook account and you validate that in your app for this you need to set Default values of the app. To fetch this information you need to this syntax “SetDefaultApplication”(As in line 2 in above code)
  • Validate: To ensure that above-set default session information valid or not you need this syntax. This syntax check appID & Secret code you enter right or not. Also ensuring that expiring time of app is not passed.
  • newAppSession: This is so much important to start session because this syntax start session according to your app authority from Facebook that means which API enabled in your app(if you do not know about this ,
  • newSessionFromSignedRequest:This finalize your session & return information to signed profile. After all validation, this sends session request from Graph API.
FacebookRequest

This allows you to get session request that you validate in above code. Here you can request for or get information according to your required. Below given code allow these all things with this syntax.

$request = new FacebookRequest(  
  FacebookSession $session,  
  string $httpMethod,  
  string $path, 
  array $params = NULL,
  string $version = NULL
);

 

// Make a new request and execute it.
try {
  $response = (new FacebookRequest($session, 'GET', '/me'))->execute();
  $object = $response->getGraphObject();
  echo $object->getProperty('name');
} catch (FacebookRequestException $ex) {
  echo $ex->getMessage();
} catch (\Exception $ex) {
  echo $ex->getMessage();
}
// You can chain methods together and get a strongly typed GraphUser
$me = (new FacebookRequest(
  $session, 'GET', '/me'
))->execute()->getGraphObject(GraphUser::className);
echo $me->getName();

 

The above code copy from Facebook developer doc. Let’s have a description on this:-

Few key methods for use of Facebook request:

  •  execute (): This basically uses to execute code & return value. This also performs network check for failure issue.  
  • getPath (): This Return a copy of the request.
  • getParameter (): This returns a copy of parameter in the request.
  • getSession (): This return session which associates with the request.

Above references from facebook dev. help from where you can read more 

I skip all the references for PHP you can learn about that on facebook help.Now we let start making a trial app.

Siteground
Features
Pricing
Server Uptime
Customer support

Pros

  • Best Customer Support
  • 99.9% server Uptime
  • Affordable hosting price
  • Free SSL
  • Managed hosting

Cons

  • VPS hosting is not good

About the author

Aman yadav

Article writer @ Liveurlifehere Blog : I am writing on Top trending article on web,technology-how to,entertainment,top n category post .I am always try to reach you diffrent & good quality content then ever.

1 Comment

Leave a Comment