You are on page 1of 21

Building real-time updates

for the Graph API

Glue Con
May 27th, 2010
Monica Keller

Wednesday, June 2, 2010


The Graph API
▪ http://graph.facebook.com

▪ New, simple, RESTful API for accessing


data on the Facebook graph
▪ OAuth 2.0-based authentication and
authorization
▪ JSON modeling of objects and
connections.

Wednesday, June 2, 2010


- at f8 we launched the graph api

- focused on developer simplicity


- allows access to objects and connections

If you take a user as the central object then their connections are their photos, videos, status updates,friends, etc
Querying the Graph API
https://graph.facebook.com/ciberch/friends?
access_token=xxx
"data": [
{
"name": "Amber Reyngoudt",
"id": "988928928928"
},
{
"name": "Ari Steinberg",
"id": "33049"
}
...
]

Wednesday, June 2, 2010


Quick example shows how easy it is to get data from the Graph API

Because our graph is so rich think of the power of using this social data to build you service
Subscribing to get updates
A hypothetical example

Wednesday, June 2, 2010


One of the applications using this information today is music service Spotify

Here is an example of how Spotify or a service like it could benefit from using the realtime api to help their users discover content in real time inside their application.
Wednesday, June 2, 2010
Spotify is a music service which allows users to play music from a desktop application. Today you can share music you like with your friends on Facebook.
Creating the subscription
A hypothetical example

1) POST /APP_ID/subscriptions

Wednesday, June 2, 2010


This is what you need to do to subscribe to get updates when the user’s of your application change friends.
Creating the subscription
A hypothetical example

1) POST /APP_ID/subscriptions
POST /APP_ID/subscriptions HTTP/1.1
host: graph.facebook.com

access_token=kawaiEJWUC2gLaanGfKy
object=userfields=friendscallback_url=http%2A%2F
%2Fwww.spotify.com%2Fsubs
verify_token=oh29hlq

Wednesday, June 2, 2010


This is what you need to do to subscribe to get updates when the user’s of your application change friends.
Creating the subscription
A hypothetical example

1) POST /APP_ID/subscriptions

2) GET callback URL

Wednesday, June 2, 2010


When Facebook receives this request it checks to make sure the callback url is valid and understands the request by echoing the challenge
Will and I become friends
so Spotify receives a callback

{"object": "user",
"entry":
[ "uid": 608201527, "changed_fields": [
"friends" ],
"time": 1274903155
]
}

Wednesday, June 2, 2010


…Moments later Will and I become friends

After this request, an outgoing call is made to the graph api passing the user’s access token

The data is then sent to the client


Querying the Graph API
https://graph.facebook.com/ciberch/friends?
access_token=xxx
"data": [
{
"name": "Amber Reyngoudt",
"id": "988928928928"
},
...
{
"name": "Will Norris",
"id": "1212123330498"
}
]

Wednesday, June 2, 2010


Spotify can then query the graph API again passing the user’s access token.

Because a lot of this data is private so only friends can see it


We don’t get the thundering herd issue
Wednesday, June 2, 2010
Push the changes from Spotify Server to Spotify client and the user will not need to close and re open the app to see their new friend.

Note: the real-time updates are server to server only. To push to the client developers can use existing connections.
Wednesday, June 2, 2010
Push the changes from Spotify Server to Spotify client and the user will not need to close and re open the app to see their new friend.

Note: the real-time updates are server to server only. To push to the client developers can use existing connections.
Wednesday, June 2, 2010
Shows how new content is being discovered via my friends in real
time
Wednesday, June 2, 2010

and we’re doing all of this using webhooks.


- but doesn’t PubSubHubbub build on top of webhooks?
PubSubHubbub
V 0.3
▪ Simple: Atom and HTTP Callbacks
▪ Performs efficiently for content
which can be fanned out
▪ Decentralized: When there is
public content
▪ Open source reference
implementations available

Wednesday, June 2, 2010


- So yes, PubSubHubbub builds on top of webhooks but offers a few distinct features
- if you’re not super familiar with it, here’s an overview of where the protocol stands today
Why not PubSubHubbub?

Wednesday, June 2, 2010


- PubSubHubbub is awesome. It builds useful semantics on top of webhooks.
- It’s really designed around making Atom and RSS feeds real-time, which means
- our engineers really found three reasons why they couldn’t use PubSubHubbub as it is today when building a real-time API
1 Non-public data

2 Data formats

3 Synchronization directives

Wednesday, June 2, 2010


1) Authorization
via OAuth 2.0
▪ The Graph API contains both public and private
data that the user has decided to share.
▪ PubSubHubbub does not authenticate the
subscribers
▪ It was designed for public feeds
▪ Solution: Add OAuth 2.0 for Subscription and
Publish requests

Wednesday, June 2, 2010


2) Data formats
Not just feeds
▪ PubSubHubbub currently only supports Atom and
RSS
▪ PubSubHubbub is built around using feeds to
model data
▪ We need to model changes in objects using JSON
▪ Monica likes Glue Con
▪ Monica changed her email address
▪ Monica is now friends with Eric Norlin
▪ Solution: Use HTTP headers for hub discovery in
non-XML based formats.

Wednesday, June 2, 2010


POST, DELETE,
PUT
3) Synchronization directives
▪ Since we are modeling changes to objects we need a mechanism to tell
the recipient what to do with the new data we sent
▪ Did the object get deleted ?
▪ Did it get updated ?
▪ Does it need to be added to a list ?
▪ Recommendation: Use HTTP methods: DELETE and PUT in addition of
POST as if the Hub was making a RESTful method call

Wednesday, June 2, 2010


We use light pings today but this is not a change we are proposing for the PubSubHubbub spec.

We are considering offering the alternatives


Thanks! Questions ?
Wiki
http://code.google.com/p/pubsubhubbub/wiki/Pshb_OAuth2

Email:
Monica Keller
ciberch@facebook.com

Wednesday, June 2, 2010


- while I’ve sent these thoughts out to the mailing list, I’m really hoping to keep this discussion going
- PubSubHubbub already has strong traction and my hope is that with a few optional changes it can be used by developers building APIs and not just producing feeds
- Thank you.

You might also like