O'Reilly logo

Facebook Application Development with Graph API Cookbook by Apeksha Singh, Shashwat Srivastava

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

Creating a "Your Good Luck Charm of the Day" Facebook application

In this recipe, we will create a Facebook application called "Your Good Luck Charm of the Day". It will forecast the name of the user's friend who will bring him/her good luck. The friend will be selected randomly. Let's begin creating this application.

Getting ready

You should have created config.php and index.php as mentioned in the beginning of this chapter.

How to do it...

The following steps will describe the creation of the application:

  1. Open index.php and add the following code before the <html> tag. Get the user's friends' details by using the api() function:
    <?php
      $friends = $facebook->api('/me/friends');
  2. Choose a friend as a Good Luck Charm of the Day randomly:
     $rand_key = array_rand($friends['data']); ...

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