Developing Facebook Platform: Extracted From
Developing Facebook Platform: Extracted From
This PDF file contains pages extracted from Developing Facebook Platform, published by
the Pragmatic Bookshelf. For more information or to purchase a paperback or PDF copy,
please visit http://www.pragprog.com.
Note: This extract contains some colored text (particularly in code listing). This is
available only in online versions of the books. The printed versions are black and white.
Pagination might vary between the online and printer versions; the content is otherwise
identical.
Copyright © 2008The Pragmatic Programmers, LLC.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any
means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher.
Beta
Book
Agile publishing for agile developers
Figure 2.1: Facebook asks you to install an application before you use
it.
1. http://apps.facebook.com/karate_poke
advertising in the canvas, but not the profile. Along with just displaying
information, an application can also add actions to its users’ profiles.
While you’re on your profile page, scroll up and look at the links under
your picture. You should see an “View your battles” link. Profile actions
are a way that Facebook encourages interaction between users.
We’ll look at the profile area in more detail in Section 7.3, The Facebook
Profile In Depth, on page 113. Let’s move on to the last major part of a
Facebook application.
Messages
Along with giving you access to the canvas and profiles, the Facebook
Platform also gives you several different types of messages. Your appli-
cation can send requests, notifications and newsfeed items. This may
seem like a lot of different message types, but they all fill very different
needs. If you’re a Facebook veteran, you’ve probably used all of these
message types without even noticing.
A request is exactly what its name implies, a request to perform an
action. When somebody asks to be your friend, that’s a request. A
Request is just a message with buttons for performing actions. Your
application can send requests on behalf of a user, but only to their
friends. Users must approve requests before they are sent. You can see
the approval process in Figure 2.2, on the next page.
Notifications are similar to Requests but lack the call to action. Your
application can send notifications on behalf of the user without requir-
ing their interaction. Unlike a request which can only be sent to a user’s
friends, notifications can be sent to any user of your application. Noti-
fications also do not require an explicit approval from the sending user.
Facebook limits the number of notifications that an application can
send for a user in a given day. Users can choose to block notifications
from certain applications, and can even mark a notification as spam. Be
careful sending notifications. If enough users mark your notifications
as spam you’ll lose the ability to send notifications for 30 days.
Newsfeed items are the last form of communication available to the
application developer. Newsfeed items are what populate your mini
feed. They tell your friends a little bit about what you’ve been doing.
Your application can send quite a large number of newsfeed items each
day but they aren’t guaranteed to be visible. Facebook tries to decide
what is interesting for each user and only shows a subset of the avail-
able items.
If you’ve used Facebook for a while, you may wonder why I haven’t
mentioned Facebook messages. Facebook doesn’t provide an API for
sending a message on behalf of a user. There are ways to help users
send messages, but they don’t have the nice integration that these other
options provide.
When a user requests a page from Facebook, they send the request on
to you. Your application responds with your content. Facebook then
puts your page into the middle of theirs and sends it back to the
browser. You can see a picture of this in Figure 2.3
This all happens seamlessly from your users’ perspective. In fact, it’s
pretty seamless from your standpoint as well. For the most part, you
can forget about Facebook standing between you and the user. Sure,
it’s not exactly like regular development, but it’s pretty close.
This may seem like a complex architecture, but Facebook has a good
reason for the complexity. By acting as a middleman, Facebook can
process the page you send back to the user. This allows them to insert
your page into their layout, and also to provide you with some really
powerful tools. We’ll look at this in detail in Chapter 5, Getting Into the
Facebook Canvas, on page 66.
Things are different for the Profile. I have ten applications installed on
my profile page. If each application took even a second to respond, it
would take ten seconds to load my profile! To prevent long profile load
times, Facebook caches profile information. You can update it at any
time by just sending them new content to display. This can feel a little
painful at first, but you’ll be happy to avoid the millions of page views
Visit Us Online
Developing Facebook Platform Applications With Rails’ Home Page
http://pragprog.com/titles/mmfacer
Source code from this book, errata, and other resources. Come give us feedback, too!
Contact Us
Phone Orders: 1-800-699-PROG (+1 919 847 3884)
Online Orders: www.pragprog.com/catalog
Customer Service: [email protected]
Non-English Versions: [email protected]
Pragmatic Teaching: [email protected]
Author Proposals: [email protected]