Create a Facebook Application With PHP
By Justin Laing2008-01-07
Hello Facebook!
Let’s create a really simple first application that just says hello to the current Facebook user. Here’s the code for the Hello Facebook! application:
<?php
/* include the PHP Facebook Client Library to help
with the API calls and make life easy */
require_once('facebook/client/facebook.php');
/* initialize the facebook API with your application API Key
and Secret */
$facebook = new Facebook(YOUR_API_KEY,YOUR_SECRET_CODE);
/* require the user to be logged into Facebook before
using the application. If they are not logged in they
will first be directed to a Facebook login page and then
back to the application's page. require_login() returns
the user's unique ID which we will store in fb_user */
$fb_user = $facebook->require_login();
/* now we will say:
Hello USER_NAME! Welcome to my first application! */
?>
Hello <fb:name uid='<?php echo $fb_user; ?>' useyou='false' possessive='true' />! Welcome to my first application!
<?php
/* We'll also echo some information that will
help us see what's going on with the Facebook API: */
echo "<pre>Debug:" . print_r($facebook,true) . "</pre>";
?>
So what happens when a user hits the Canvas Page URL (from the example it would be: http://apps.facebook.com/makebeta/)? The require_login() call will produce a screen like this for the user:

If you change require_login() to require_add() the user will get a page that looks like this:

After the user logs into or adds the application they will get the canvas page with the “Hello…” text. It should look something like this:

Tutorial pages:
|
Originally posted on Makebeta
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "Create a Facebook Application With PHP"
You must be logged in to post a comment.
Link to This Tutorial Page!

