Facebook’s “Hello, World!” Sample PHP Script

Finally got my first Facebook application to work … for a while there, I was stuck at ‘Hello’:

RE: ‘the user’s name doesn’t display’

Here is the code I used for Facebook’s Hello, World! sample PHP script:

Code:

<?php
/* include the PHP Facebook Client Library to help
with the API calls and make life easy */
require_once('../platform/php/facebook.php');

// some basic library functions
include_once 'lib.php';

// this defines some of your basic setup
include_once 'config.php';

/* initialize the facebook API with your application API Key
and Secret */
$facebook = new Facebook($api_key,$secret);

/* 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='false' />! Welcome to my first application!

The user’s name does not display if you view your application from your server.  You have to be logged into Facebook and go to http://apps.facebook.com/<yourapp>

REF:

Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: