In Detail

With a user base of nearly 800 million people, Facebook is the number one social networking platform. Applications can be created to interact with this huge user base in various ways both inside and outside Facebook. These applications, if developed effectively and efficiently, offer a free medium for promotion and publicity of a product or an organization.

Facebook Application Development with Graph API Cookbook covers both the concepts and implementations necessary to develop Facebook applications and provides ready to use code for common scenarios faced by a developer while creating these applications. It incorporates the newly launched Facebook Graph API and also presents the reader with some intuitive ready to use applications.

This book guides the reader step by step, from start to finish, through various stages of Facebook application development. It begins by exploring the Facebook application registration and discussing the verification and authentication technique. It then takes you through the various ways in which you can use Facebook Graph API for interacting with users such as posting on a user’s wall, tagging a user in a picture, etc. Accessing complex Facebook user data by formulating a series of queries, doing client side scripting and incorporating Facebook Dialog interface are some other features that have been incorporated in this book. Integration of various Facebook Social Plugins such as the like box in your web page has also been discussed. Further you will get to know the concept of virtual currency and how to programmatically derive Facebook analytics data. As the book progresses, you will learn to use and integrate many more advanced features in Facebook application development. The book contains ready to use code that can be deployed instantly. Towards the end, the book houses a variety of ready to use Facebook applications so as to help readers derive their own applications from them.

Authors

Shashwat Srivastava

Shashwat Srivastava has been an avid coder since high school and has acquired technical proficiency in various programming languages with over 12 years experience. He is a strong advocate of open source tools and hosts his projects at SourceForge. He has successfully participated in Google Summer of Code Programs 2010 and 2011. He graduated as Bachelor in Electronics and Communication from Delhi College of Engineering in 2011. During his college days, Shashwat published websites for several clients including his college library and electronics department. Currently, he is working as an application developer at Oracle. He actively contributes to Drupal and has developed modules such as DrupalChat, DXMPP and Chatroom. His keen interest lies in web application development and as a result he has built several Facebook and Twitter applications. Passionate about programming he loves to blog about PHP, JavaScript, MySQL, Linux, Android and other insanities at http://www.botskool.com. When unplugged, he enjoys playing chess and computer games.

Apeksha Singh

Apeksha Singh is a software engineer and an open source hobbyist and enthusiast. She has recently graduated as a Computer Science Engineer from Jaypee Institute of Information Technology and has extensive experience in web development and search engine optimization. She has authored articles and research papers in these fields. She has programming experience of seven years and loves data structure. Obsessed with new technology, Apeksha keeps track of the latest developments in the tech world and likes to update others and share her views by blogging at http://www.botskool.com. She has also worked in the field of embedded systems and robotics. In her free time, she reads novels and plays sports such as badminton and tennis. She can be reached at her personal blog - http://apeksha0701.blogspot.com.

Table of Contents

Chapter 1: Creating a New Facebook Application

Introduction

Downloading PHP-SDK and setting upyour environment

Registering a new Facebook application

Configuring a Facebook application

Getting authorization and a valid session for the user

Requesting specific permissions from the user

Logging out a user

Handling navigation in an iFrame Facebook application

Handling form submission in an iFrame Facebook application

Dynamically resizing an iFrame Facebook application

Determining whether a Facebook page has been liked by a user

Chapter 2: Be a part of Social Graph

Introduction

Retrieving a user's information

Liking a post

Commenting on a given post

Setting status message

Deleting a picture, post, or comment of a user

Retrieving the current user's friendlist

Creating a post on the wall of a user's friend

Posting a picture to a specific album of the user

Retrieving the names of the user's friends who have liked a particular status message

Creating an event

Paging through a user's friends

Searching through a user's feed

Tagging users in a picture

Adding a subscription for real time updates related to a user object

Creating a callback for handling real time updates

Deleting subscriptions

Chapter 3: Querying Facebook

Introduction

Returning information about a user

Getting the status messages of a user

Retrieving profile pictures of a user's friends

Getting the links posted by a user

Getting the Facebook pages followed by a user

Determining if two users are friends

Retrieving information of a group

Retrieving members of a group

Retrieving friends from a specific friend list

Getting all the messages in a thread

Checking the status of permissions for an application

Getting notifications, and their senders, for the current user

Retrieving video details associated with a user

Getting the five latest photos in which a user has been tagged

Retrieving the latest photos published by a user

Retrieving details of an event

Retrieving details of a user's friends by using the multiquery method

Chapter 4: Using FB Script

Introduction

Getting the current user status and performing session validation

Setting up extended permissions during login

Logging out a user

Resetting the size of iframe

Making a Graph API call

Executing an FQL query

Subscribing to an event change

Unsubscribing to an event change

Retrieving a profile picture using XFBML

Adding bookmarks using XFBML

Authentication and setting up extended permissions using XFBML

Chapter 5: Expressing Yourself

Introduction

Prompting the user to publish a story

Using Dialog to add someone as a friend

Using the OAuth Dialog to request permissions for your application

Prompting the user to send a request to friends

Processing requests sent to the user by friends

Chapter 6: Bringing Facebook to your Website

Introduction

Setting up the Like button on your web page

Adding a Like box

Setting up the Activity Feed plugin

Setting up the Facepile plugin on your web page

Integrating the Live Stream plugin using XFBML

Integrating the Comment box using XFBML

Integrating the Send button using XFBML

Login with Faces

Chapter 7: Connecting Websites to the Social Graph

Introduction

Integrating web pages into the social graph

Integrating audio and video data

Administering your page

Publishing stream updates to the users

Chapter 8: Fiddling with Virtual Currency

Introduction

Setting up the application for Facebook Credits

Setting up an application callback for Facebook Credits

Creating Facebook Credits frontend using JavaScript SDK

Getting the order details

Implementing custom offers

Refunding the order

Developing a "Send a Gift" application and integrating with Facebook Credits

Chapter 9: Creating Advertisements and Analyzing Metric Data

Introduction

Retrieving impressions of the Like Box plugin

Retrieving a page's stream views and wall posts using batch request

Getting the number of installations of an application using FQL

Getting statistics about visitors using FQL multiquery

Creating a new ad for your Facebook application

Chapter 10: Creating Instant Applications

Introduction

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

Designing a "My Fast Friends" Facebook application

Setting up a photo collage

Building a birthday calendar

Developing an application to classify friends according to the cities they live in

Alerts & Offers

Series & Level

We understand your time is important. Uniquely amongst the major publishers, we seek to develop and publish the broadest range of learning and information products on each technology. Every Packt product delivers a specific learning pathway, broadly defined by the Series type. This structured approach enables you to select the pathway which best suits your knowledge level, learning style and task objectives.

Learning

As a new user, these step-by-step tutorial guides will give you all the practical skills necessary to become competent and efficient.

Beginner's Guide

Friendly, informal tutorials that provide a practical introduction using examples, activities, and challenges.

Essentials

Fast paced, concentrated introductions showing the quickest way to put the tool to work in the real world.

Cookbook

A collection of practical self-contained recipes that all users of the technology will find useful for building more powerful and reliable systems.

Blueprints

Guides you through the most common types of project you'll encounter, giving you end-to-end guidance on how to build your specific solution quickly and reliably.

Mastering

Take your skills to the next level with advanced tutorials that will give you confidence to master the tool's most powerful features.

Starting

Accessible to readers adopting the topic, these titles get you into the tool or technology so that you can become an effective user.

Progressing

Building on core skills you already have, these titles share solutions and expertise so you become a highly productive power user.