development a “hello world”application with facebook api

posted in: Program, Project, Research

first of all, you need download facebook PHP Client Libraries. Extract package to you work path. open the directory, there are two sub-directory, PHP directory is libraries, you need use it to develop application. and a example directory called foodpoints. Open PHP directory, creating two PHP files – index.php and config.php.

In config.php:

<?php
$api_key = '[API_KEY]';&amp;amp;nbsp; // your apps api key
$secret&amp;amp;nbsp; = '[SECRET_KEY]'; // your apps secret key
$backurl="http://liduan.com/fb/start";&amp;amp;nbsp; your call back web url
?>


In index.php:

<?php
	include_once 'facebook.php';
	include_once 'config.php';

	$facebook = new Facebook($api_key, $secret);
	$facebook->require_frame();
	$user = $facebook->require_login(); // check user is login

	try{
	if(!$facebook->api_client->users_isAppAdded()){
		$facebook->redirect($facebook->get_add_url()); // check user is add this apps
		}

	}catch(Exception $ex){
		$facebook->set_user(null,null);
		$facebook->redirect($backurl);

	}

	// main
	echo "<p>Hellow</p>";
	echo "<p>world</p>";
	echo "<p>this is developed by <a href='http://liduan.com'>liduan.com</a></p>";

	?>

finish coding, upload whole php directory to web space that must support PHP5 and make sure public can access it. example http://liduan.com/fb/start

Next, adding apps to facebook, open http://developers.facebook.com, click ‘Get Start’ -> “Add Facebook Developer Application” -> “Setup New Application” you will see a form of add new application. there are some very important options you must fill it.

  1. Application Name: I remember this name can’t include ‘face’ and ‘application’.
  2. developer Contact email and user support email is your and your partner email.
  3. Callback URL: you can find it in config.php. that’s you apps hosting address.
  4. Canvas Page URL: format is http://apps.facebook.com/[YOUR CANVAS PAGE URL]/ can not same with other apps, and not allow number.
  5. Application Type is Website.
  6. Can your application be added on facebook? if you choice ‘no’, that means nobody can find your apps in facebook apps list.
  7. Post-Add URL is same with Canvas Page URL : http://apps.facebook.com/[YOUR CANVAS PAGE URL]/
  8. Default FBML: you can fill ‘hello world’
  9. Side Nav URL is also same with Canvas Page URL : http://apps.facebook.com/[YOUR CANVAS PAGE URL]/

submit form, you will find your api key and secret key. put them to you config.php and upload again. Now. open your call back url, and follow by facebook guide and add this app to your facebook account. you will see “hello world”.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • email
  • HelloTxt
  • Live
  • MyShare
  • MySpace
  • Tumblr
  • Twitter
  • Yahoo! Bookmarks
  • Yigg
  • BlogMemes Fr
  • Fark
  • FriendFeed
  • Haohao
  • LinkedIn
  • MisterWong
  • PDF
  • Ping.fm
  • RSS
  • Slashdot
  • Socialogs
  • Technorati

This entry was posted on October 29, 2008 at 7:55 pm and is filed under Program, Project, Research (Tags: , , , ). You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Comments (11)

Leave a Reply