News

This blog has been shifted to Innovation Escalator.

Wednesday, May 11, 2011

Apps on Facebook.com

Hello everyone I'm here to discuss about how to build a Facebook App. Facebook has millions of user with it and developing an app on Facebook gets you opportunity to deeply integrate into the core Facebook experience. An app developed on Facebook can integrate with many aspects of Facebook.com, including the News Feed and Notifications. Apps on Facebook are the web apps that are loaded in context of Facebook. And a web app can we developed by any of the available languages, the further Blog is based on php.

The apps on facebook are canvas based, we have a canvas (or iframe) in which we load our app.
Suppose the url to your app is http://www.stalwartvision.com/canvas then the app url will be http://www.apps.facebook.com/your_app_name (i.e. this url will load the contents of your original app link).Before getting into anything lets know the size of canvas so that we can build our app efficiently.  
760px (width) - if you build your app on a full app page, and
520px (width) - if you embed your app on a page in Facebook.com

Facebook Integration

Firstly you need to goto Developer App click on Set Up a New App, further you will be asked to enter the name of your app, do it and proceed, cross the security checks and all and doing all that you will be redirected to a page where you need to enter the basic information about your app and this page will also contain the tab Facebook Integration. Under this tab you will get your app_id and app_secret, you need to note these two because they will be used further in your app. Your canvas url gets integrated to facebook now what you need to do is start developing your app.


I can't give you an idea of what an app to develop, so am just proceeding with how to use the facebook pre-defined functions in your app and access the user information. You need a facebook.php, which contains all the required pre-defined functions to be used. A sample code to use these functions and access user information on Facebook is -

 <?php
// Awesome Facebook Application (shubham0987@gmail.com)require_once 'facebook.php';
// Create our Application instance.$facebook = new Facebook(array(  'appId' => 'your_app_id',  'secret' => 'your_app_secret',  'cookie' => true,));
    $app_id = "your_app_id";    $app_secret = 'your_app_secret';    $canvas_page = "your_canvas_url";    $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id . "&redirect_uri=" . urlencode($canvas_page);    $code = $_REQUEST["code"];    $token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$app_id."&redirect_uri=". urlencode($canvas_page)."&client_secret=".$app_secret."&code=".$code;       if (empty($code)) {echo("<script> top.location.href='" . $auth_url . "'</script>");}        $access_token = file_get_contents($token_url);        $user_data_url = "https://graph.facebook.com/me?".$access_token;        $user = json_decode(file_get_contents($user_data_url));
echo("Username:" . $user->name);
echo("Email" . $user->email);
         ?>
The above code will fetch user-name on facebook.com and his email-id, you can use this code for your app and further modify it, there are multiple ways to do it but i find it the simplest. This would be the starting or basic step of your Facebook app use this and get a burning idea for your app and show your programming skills and get your app working on Facebook.com.



Hope your find it useful... hope to see your app soon... :)

No comments:

Post a Comment