5

What is the counterpart of Twitter Streaming API for Facebook Fan Page?

How can i get real time updates from a Facebook Fan Page?

Alex Bitek
  • 6,529
  • 5
  • 47
  • 77
Mesut
  • 916
  • 1
  • 7
  • 17

1 Answers1

2

You have to use the realtime api from facebook : http://developers.facebook.com/docs/api/realtime/

To do what you ask, you must subscribe to page objects and their feed connection.

To add a subscription you have to send a POST request to :

https://graph.facebook.com/<app-id>/subscriptions?access_token=...

And for that you need an access token that you can get at :

https://graph.facebook.com/oauth/access_token?client_id=<app-id>&client_secret=<app-secret>&grant_type=client_credentials

The fields that have to be in the POST data are :

  • object - The type of the object to monitor, e.g. “user” or “permissions”. You will monitor all objects of that type; for example, all users of your application.
  • fields - A comma-separated list. This is a list of properties or connections on the specified object. For example, to monitor changes to user's name, picture, friends, and News Feed, you would specify “name,picture,friends,feed”
  • callback_url - A callback URL to which Facebook will post subscription updates.

And you can specify

  • verify_token - A subscriber-provided opaque token that will be echoed back in the verification request to assist the subscriber in identifying which subscription request is being verified. If this is not included, no token will be included in the verification request. This is from the PubSubHubbub spec.

Once your callback url has been verified, you will receive updates when data change in the feed of the page on your callback url as json objects, here is an example for a user :

{
"object": "user",
"entry": 
[
    {
        "uid": 1335845740,
        "changed_fields": 
        [
            "name",
            "picture"
        ],
       "time": 232323
    },
    {
        "uid": 1234,
        "changed_fields": 
        [
            "friends"
        ],
       "time": 232325
    }
]
}

You can also do GET and DELETE on the same URL to get the list of your subscriptions, and to delete subscriptions.

But all the details are in the facebook doc

dwarfy
  • 3,076
  • 18
  • 22
  • 3
    One small difference however is that unlike Twitter streaming api, Facebook real-time updates doesn't give the actual change as feed. It just indicates that there is an update on the said object. One then has to explicitly pull the object and figure out the change. – Balakrishnan Apr 29 '11 at 00:18
  • is there any sample code available in Ruby? I searched a bit but seems not so many is using realtime graph api... it is a bit weird. – Mesut Apr 29 '11 at 07:43
  • In theory this now works to get wall updates on a page, but I can't get it to work. – Leopd Sep 09 '11 at 21:46