02_277959-ftoc.qxp 5/5/08 11:24 AM Page vii

Contents at a Glance

Introduction ...... 1 Part I: Getting Friendly with the Platform...... 7 Chapter 1: Introducing Facebook and the ...... 9 Chapter 2: The App Walkabout: Building Your First Facebook Application...... 29 Part II: Poking the API ...... 47 Chapter 3: Working with the Facebook API...... 49 Chapter 4: Writing Facebook Markup Language (FBML) ...... 95 Chapter 5: Exploring FQL: Facebook Query Language...... 121 Chapter 6: Scripting with Facebook JavaScript...... 143 Chapter 7: “Goin’ API” with Facebook Developer Tools...... 167 Part III: Developing Facebook Applications ...... 177 Chapter 8: Developing Facebook Canvas Pages...... 179 Chapter 9: Creating Content for Profile Pages...... 195 Chapter 10: Seamless Styles: Styling Your Facebook Application...... 215 Chapter 11: Hear Ye, Hear Ye: Communicating with the and Notifications ...... 235 Chapter 12: Tying It All Together: Speed Dial Application...... 249 Part IV: The Part of Tens ...... 299 Chapter 13: Ten Strategies to Exploit the Power of the Facebook Platform...... 301 Chapter 14: Ten Killer Facebook Applications to Explore ...... 313 Chapter 15: Smashing Successes: Ten Tips for Making Your Application Popular...... 321 Index ...... 327COPYRIGHTED MATERIAL 02_277959-ftoc.qxp 5/5/08 11:24 AM Page viii 02_277959-ftoc.qxp 5/5/08 11:24 AM Page ix

Table of Contents

Introduction...... 1 About This Book...... 1 Foolish Assumptions ...... 2 Conventions Used in This Book ...... 2 What You Don’t Have to Read ...... 3 How This Book Is Organized...... 3 Part I: Getting Friendly with the Facebook Platform ...... 3 Part II: Poking the API ...... 3 Part III: Developing Facebook Applications ...... 4 Part IV: The Part of Tens...... 4 Icons Used in This Book...... 4 Where to Go from Here...... 5 Sample Files for This Book...... 5

Part I: Getting Friendly with the Facebook Platform ...... 7

Chapter 1: Introducing Facebook and the Facebook Platform ...... 9 Discovering Facebook ...... 10 News Feed ...... 10 Profile...... 12 Discovering the Pulse of Facebook: The ...... 15 What Is the Facebook Platform?...... 16 Points of integration ...... 16 Facebook application architecture ...... 22 Exploring the Framework Components...... 24 Facebook API ...... 24 Facebook Markup Language ...... 25 Facebook Query Language...... 25 Facebook JavaScript ...... 26 Chapter 2: The App Walkabout: Building Your First Facebook Application ...... 29 Registering an Application with Facebook ...... 30 Creating a Simple Facebook Application ...... 37 Adding an Icon to the Application ...... 41 Setting the Initial Content of the Application’s Profile Box ...... 42 Adding an About Page ...... 43 02_277959-ftoc.qxp 5/5/08 11:24 AM Page x

x Building Facebook Applications For Dummies

Part II: Poking the API ...... 47

Chapter 3: Working with the Facebook API ...... 49 Calling the Facebook API...... 49 Evaluating What Comes Back from Facebook ...... 55 Getting Friendly with Friends ...... 56 Getting friends with friends.get...... 57 Evaluating friends with friends.areFriends ...... 58 Getting friends who are app users with friends.appUsers...... 60 Accessing Events...... 62 Getting the events of a user ...... 62 Getting the members of an event ...... 69 Getting Cozy with Groups ...... 72 Getting groups with groups.get ...... 73 Retrieving member info with groups.getMembers ...... 80 Facebook Pages...... 83 Getting page information with pages.getInfo...... 84 Scoping out with pages.isAppAdded ...... 86 Getting current user info with pages.isAdmin and pages.isFan .....87 Pulling User Data...... 87 Getting the current user with users.getLoggedInUser ...... 87 Getting info with users.getInfo ...... 88 Checking whether a user has your app with users.isAppAdded ...93 Checking permissions with users.hasAppPermissions...... 93 Chapter 4: Writing Facebook Markup Language (FBML) ...... 95 Exploring FBML ...... 95 Working with Users and Groups...... 103 Displaying Content Conditionally ...... 106 Testing on canvas pages...... 107 Showing and hiding content in profile boxes ...... 109 Using fb:if and fb:switch ...... 111 Adding Facebook UI Elements and Widgets ...... 112 Discussing it on the board ...... 113 Another comment on the Wall...... 114 Building a Wall post by post ...... 115 Creating Requests and Invitations...... 116 Building a standard-sized request form ...... 116 Building a condensed request form...... 120 Chapter 5: Exploring FQL: Facebook Query Language ...... 121 Discovering Why SQL + Facebook API = FQL...... 121 Comparing FQL and API access...... 122 Making an FQL statement...... 123 Differences between SQL and FQL ...... 123 02_277959-ftoc.qxp 5/5/08 11:24 AM Page xi

Table of Contents xi

Writing a Basic Query...... 124 Changing the field order in the result set...... 127 Dealing with array-type fields...... 128 Using operators in the WHERE clause...... 128 Writing More Complex Queries with the IN Operator...... 129 Using Special Functions ...... 139 Chapter 6: Scripting with Facebook JavaScript ...... 143 Understanding the Facebook Platform Scripting Approach...... 143 Accessing the DOM...... 144 Setting the Content of DOM Elements...... 147 setInnerXHTML()...... 147 setInnerFBML()...... 147 setInnerText() ...... 148 Setting Styles through FBJS ...... 148 Including External JavaScript Files on Canvas Pages...... 149 Helpful Tips When Using FBJS...... 150 Using the FBJS Animation Library ...... 150 Tweening animation...... 152 Adjusting the speed and ease of the animation ...... 156 Adjusting the size and visibility of block-level events...... 156 Working with AJAX in FBJS ...... 159 Chapter 7: “Goin’ API” with Facebook Developer Tools ...... 167 Working with the API Test Console...... 168 FBML Test Console ...... 170 Feed Preview Console...... 173 Debugging FBJS with Firebug...... 176

Part III: Developing Facebook Applications ...... 177

Chapter 8: Developing Facebook Canvas Pages ...... 179 To FBML or iframe? That Is the Question ...... 179 Adding a Navigation Header Using FBML ...... 181 Adding an fb:dashboard element ...... 183 Adding a tab set with fb:tabs and fb:tab-item...... 185 Adding a header with fb:header ...... 188 Creating an Editor Form Page...... 190 Chapter 9: Creating Content for Profile Pages ...... 195 Discovering Profile Boxes and Action Links...... 195 Profile box ...... 196 Profile action links...... 197 Configuring the Default Profile Settings ...... 198 02_277959-ftoc.qxp 5/5/08 11:24 AM Page xii

xii Building Facebook Applications For Dummies

Pushing Profile Content with profile.setFBML ...... 199 Working with Content in the Profile Box...... 201 Adding Action Links to a User Profile...... 212 Chapter 10: Seamless Styles: Styling Your Facebook Application ...... 215 Adding Styles to Your FBML ...... 215 Using inline styles ...... 216 Using embedded styles...... 216 Including external style sheets...... 218 Specifying Wide and Narrow Styles for Profile Boxes ...... 218 Using fb:ref to Load CSS in a Profile Box...... 219 Going Native: Emulating Facebook Styles...... 220 Setting the basic formatting styles...... 221 Emulating the Facebook dashboard ...... 223 Creating your own navigation tabs ...... 226 Creating a subtitle region ...... 228 Emulating Facebook buttons ...... 229 Creating two-column lists...... 232 Chapter 11: Hear Ye, Hear Ye: Communicating with the News Feed and Notifications ...... 235 Publishing a News Feed Story to Current Users ...... 236 Publishing Actions to a User’s Mini-Feed and Friends’ News Feed ...... 238 Rolling Up Your Sleeves: Publishing Templatized Actions ...... 240 Exploring the template parameters ...... 241 Working with tokens ...... 242 Exploring the fbRecipe template...... 244 Registering your story template...... 245 Sending Notifications...... 247 Chapter 12: Tying It All Together: Speed Dial Application ...... 249 Coming Up with a Basic Vision...... 249 Setting Up Speed Dial in Facebook ...... 250 Creating the Speed Dial Database...... 253 Structuring the PHP Source Code ...... 254 Setting Up the Canvas Page ...... 254 Connecting to Facebook...... 255 Building the Canvas Page...... 256 Constructing the page header ...... 257 Adding a friend ...... 258 Getting a list of dial friends ...... 259 Previewing the Speed Dial...... 260 Resetting the Speed Dial...... 262 Processing user actions...... 262 02_277959-ftoc.qxp 5/5/08 11:24 AM Page xiii

Table of Contents xiii

Assembling the canvas page UI ...... 263 Styling the UI...... 266 Adding a random quote display ...... 268 Adding a page footer...... 270 Setting the Profile Box Content ...... 271 Sending Notifications and Publishing a News Feed Story ...... 275 Adding an Invitation Page ...... 278 Prepping the About Page ...... 279 Exploring the Full Source Files ...... 280

Part IV: The Part of Tens...... 299

Chapter 13: Ten Strategies to Exploit the Power of the Facebook Platform ...... 301 Optimizing Your Facebook App...... 301 Going Mobile with Your Facebook App...... 302 Working with Attachments ...... 303 Keeping Track of the Session Key...... 306 Making Canvas Pages Accessible to Non-Facebook Users ...... 307 Handling Unique Browser Needs ...... 308 Integrating with Google Analytics...... 309 Handling Redirects...... 310 Working with Cookies...... 310 Integrating with Marketplace...... 310 Chapter 14: Ten Killer Facebook Applications to Explore ...... 313 Local Picks ...... 314 iLike...... 314 Attack!...... 315 iRead ...... 316 Quizzes ...... 317 Where I’ve Been...... 317 Flixster...... 318 Top Friends ...... 318 Introplay’s Workout Olympiad and Runlicious ...... 319 Appsaholic ...... 319 Chapter 15: Smashing Successes: Ten Tips for Making Your Application Popular ...... 321 Avoid Social App Faux Pas...... 321 Think Social, Act Social ...... 322 Brand Your App Effectively...... 322 Communicate Wisely with Your Users ...... 323 02_277959-ftoc.qxp 5/5/08 11:24 AM Page xiv

xiv Building Facebook Applications For Dummies

Engage Potential Users with Your About Page...... 323 Man Your Discussion Board...... 323 Pay Attention to User Reviews and Feedback...... 324 Promote Your App on Facebook ...... 324 React Quickly to Platform Changes and Enhancements...... 324 React Quickly to User Growth ...... 325

Index...... 327