O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Code Samples

Many of the PHP code samples in this book require the Facebook API to be included and instantiated before the sample can be run. Those precious few lines of code have been omitted throughout to save space, so stick these in when you need them:

<?php
    include_once 'resources/includes/config.php';
    include_once 'resources/includes/facebook.php';
?>

<?php
global $api_key, $secret;

// Code Goes Here

?>

You’ll need to adjust the paths in the include_once lines to match where you’ve put the files after downloading them. See Chapter 5 for more information on setting up your environment.

Although there’s a lot of code in here that you could lift straight off these pages and drop into your app, remember that none of this has been extensively tested as production code and there’s very little error checking. Since Facebook throws exceptions when things blow up, I’d suggest at least wrapping your code in some try/catch statements and doing something useful with your contained explosions.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required