YOUR OWN FACEBOOK APP

Friday, February 26, 2010 , Posted by gurur@j at 2/26/2010 10:18:00 AM

setting up

YOUR OWN FACEBOOK APP


Facebook is the latest rage in the social networking arena.With in numerable apps out there,it's easy to get lost in Facebook .Find out how you can tap the excisting side of the face book by creating your own app.Before you actually start writing your application,you need to register your application with facebook and get someapplication-specific information that will be essential for your application to communicate with the facebook patform.By this,we mean the API key and the secret key that needs to be specefied in your code.


Log into your Facebook account and go to
http://www.facebook/developers .Add the application to your Facebook profile.on the top right corner,you will see the "set up new Applications"button.click on it.Given your application a name that help other identify it.Agree to facebook Terms and conditions and click on save changes.


Now that the basic stuff is in place,you'll need a logo to associate with this application.This just makes it easy for people to recognise your application through the facebook application directory.You can also add an email addressthat people can use for technical support.




Head over straight to the canvas tab.There you will see render methods.You have to choose between iFrame and FBML.For this example to be simple,we will use FBML.Choose it and click on save changes.you can also need to populate the base and callback URL for your application.Base URL is the just the fancy URL name that other people will be using to access your appliction page.Facebook will provide immediate feedback if that URLis unavailable,in which case you should pick something.The callback URL is the actual stuff that points the applciations to yourserver.Make sure you enter the URL of the folder in which your index.php and other pages are located and not the actual index.php URL.


Next head over the advanced settings option.select website for this example as we will be creating a traditional web app that integrates with a facebook and not a desktop app which accesses facebook using the API and is run like on a normal desktop application.Now go the authentication options tab.Here you can select who all can add your applications to their facebook account specify a URL textbox.It is the url that the facebook sends a notification to,once a user authorises your application.Select the wide option in the default profile box column for a rich experiences.Also fill in the URL that you want users to get redirected to after installing your applications in the post-authorised redirect URL on the canvas URL,basically the URL you typed in the base URL field earlier.






Finally,click the submit button.you will be taken to the My application page where you will get access to your API key and the secret keyalong with other meta information about your application.


Creating your Facebook application


Now that you have your API and secret key,you are ready to create an application using the facebook client library.we are more or less done on the facebook site as of now.First thing you need to do now is to download the client library.we are more or less done on the facebook site as of now.First thing you need to do now is to download the client library files of the programming language that you will be using(PHP,in our case)by going to the application page on or http://www.facebook.com/developers/apps.php .Facebook officially support PHP and java client libraries, and ASP.NET by its collaborated project with microsoft-http://www.codeplex.com/facebooktoolkit .The unofficial libraries of several othe programming languages can also be found on the facebook developers wiki http://wiki.developers.facebook.com.

The canvas page of seeting

Now you nee to uncompress the downloaded file and copy the client file libraries in the folder  that you specified as your canvas URL while setting up your

application.The PHP client library that we will using is under the main folder named facebook-platform.next you need to create a new file named appinclude.php.You can use dreamviewer to do this or even  simple text editing softwares such as notepad.This file will contain the  facebook initilisation code required by your application to connect to the facebook platform.You will have to include this file in all other PHP files in your APIkey,secret key and callback URL.

set-up application type to web
Type out the following code in the this file:



require_once  '../facebook- platform/client/facebook.php';


$appapikey = '[api_key]';


$appsecret = '[secret_key]';


$appcallbackurl = '[web_app_callbackurl];


$facebook = new


Facebook($appapikey,$appsecret);


$user = $facebook->require_login();


try{


if(!$ facebook->api_client->user_isappadded()); {


$facebook->redirect($facebook-get_add_url());


}


} catch(exception $ex) {


$ facebook->set_user(null,null);


$facebook->redirect($appcallbackurl);


}


?>






Replace the API key,secret key and the callback URL whenever required.






Next log on to your web server(your callback URL,rember?)and create a folder for your application.This is required because the facebook.php path in the require_once statement of the applinclude.php file we just wrote requires your app files to be located in a seperate parallel folder with the facebook client libraries.This step is flexibe as you can change the path of facebook.php in appinclude.php if your folder struture differs.


you are now ready to write index.php of your application.The necessary code in that file has to be-








require_once'appinclude.php';?>


These are basically the title of your application,the PHP start and end tags and require_once statement to include appinclude.php file.


You can play around this page as you desire.Let us make our application display the user's name.For this,you need to type in the following php code in your index.php after the necessary code-






echo"


we are basically using the fb:name FBLM tag to render the name of the current user.If you want to add a list of your  facebook friends,you can do this by the following code in your index.php-






echo"


$friends =$facebook->api_client->friends_get();


echo"";


foreach($friends as $friend)


{


echo "


useyou=\"false\"/>


}


echo "






To try out this application,save the file,and copy it into your application folder on your web server.Next enter the canvas page URL of your application after making sure you are logged into Facebook in your web-browser.you will be redicted to your callback URL and the index.php will be rendered back inside the facebook canvas.There's a lot moer you can do with your applicaiton.For starters,we could do the following:






Add content to the profile box of your application


you probably want your application to have some content when it appears as a box of the profile page.To set this up all you need to do is add some code of the index.php  file just after the require_once "appinclude.php"statememt.






$default_text





useyou=\"false\" />!this application is a part of a sample guide to creating your own facebook aplciations.


$facebook->api_client->profile_setFBML($default_text);


Add an about page

you also should add an about page for your application so that facebook users get to know what your application is all about.Its also an important marketing step while you are promoting your application.Go back to www.facebook.com/developers ,and click on see my apps button in the my application profile.Here is where you can also modify your application name and the description which you initially gave while setting up your application.Add up all that's relevant to your application and click on save.


























";
    ";

  • ";
    your friends:
    ";
    your user name is:
    ";

    Digit Test Applicaiton

    Currently have 0 comments:

    Leave a Reply

    Post a Comment

    ThinkBlogLab|TechnologyBlog

    up
    Latest News
    rss

    Enter your email address:

    Delivered by Think Blog Lab

    Google Earth 3D-UpComing Buildings

    Sample