Do a Facebook Application Must Needs own Database?

Technically Not. Then you may ask how check the authentication and how we tracks permissions etc. That is where the power of Facebook lies. Actually we don’t need such things. Facebook manage the way how the user interact with App, and how sign-out and sign in.

I will explain how the process works.

If you look this, you can understand its almost same as regular web application. If we divide the process of any web application it will have following stages

  1. Page accessible without
  2. Login Pages For Login
  3. Pages which see after login

Facebook is also works in the same way. But in our web apps we need session user, user profile table and authorization session checks. Here no need of that. We have all the information with as we have valid Facebook login session. Also we can use the Facebook session decide the auth.

Now the question is how the apps Auth work. Here You have three choices here

  • Apps which can see to everybody without signup
  • Apps which can viewable to only signup user

I will explain them much one by one

Apps which can see to everybody without signup

It can be any html/php(Any thing) pages without any codes for Auth. You can use any of your site to site pages while you are configuring facebook app. Technically Facebook apps is a webpage which just loading your webpage in an iframe. Nothing more than that

But while designing the app you must be care full about the two things

  • Are you like to use the App as a Page? That means that you can make the application as sub link in any of your Facebook page.If so, you with must 500px (I guess) . Else new page layout may break and scroll will come. Which make the page odd.
  • Are you like to use the App as an Application Alone? Now you can user 720px width to develop. Most of the case width defining in px will a good job than in % in Facebook Platform

Apps which can viewable to only signup user

This is what, almost all the programmers really need. To implement this we need few things you can user Facebbok Graph API. Also you can download the Facebook sample app.

A simple App can be simple as below

require

‘../src/facebook.php’;

$facebook
=
new Facebook(array(

‘appId’
=>
‘YOUR_APP_ID’,

‘secret’
=>
‘YOUR_APP_SECRET’,

));

 

// Get User ID

$user
=
$facebook->getUser();

 

if ($user) {

try {

// Proceed knowing you have a logged in user who’s authenticated.

$user_profile
=
$facebook->api(‘/me’);

} catch (FacebookApiException $e) {

error_log($e);

$user
=
null;

}

}

 

// Login or logout url will be needed depending on current user state.

if ($user) {

$logoutUrl
=
$facebook->getLogoutUrl();

} else {

$loginUrl
=
$facebook->getLoginUrl();

}

 

if ($user) {

 

echo ‘Hello Word’;

}

else

{

echo ‘You must Logn to Proceed’;?>

<a href=”<?php
echo
$loginUrl; ?>“>Login with Facebook</a>

<?php

}

 

Now the question is, how we checks whether he is already done the signup. It is quite simple

// Get User ID

$user
=
$facebook->getUser();

It will give you information if you have already got permission. So in fact you don’t need any user or auth table to manage the user signups.

Now user profile

$user_profile
=
$facebook->api(‘/me’);

The above code will get you all the possible user information’s in the user profile. So again you don’t need any table for profile

Now, next question. How much information you need from profile

For that you can user Permissions

$this->facebook->getLoginUrl(array(‘cancel_url’ => ‘CNACEL_URL’, ‘next’ => ‘NEXT_URL’, ‘req_perms’ => ’email,publish_stream’)

 

You can add more things to get more in req_perms. Reference

Last Question How can redirect the user to sign up automatically

It’s quite simple again,

echo(“<script> top.location.href='” . $auth_url . “‘</script>”);

But if you need any information to be saved, like blogging or polling you can use custom database

So you have doneJ

Hope you are become a Facebook expert.

Thanks for the Time!

 

References

  1. Facebbok Graph API
  2. Sample Facebook app.
  3. Facebook Permissions
  4.  

Subin George