Tuesday, November 9, 2010

Short PHP script to manage subscription to Facebook Realtime API

Facebook Realtime API allows reacting to changes in a user's profile in near real time.

In a nutshell, every time a user changes their friends list or their feed changes (or a number of other fields), an event is generated and transmitted via HTTP POST to a designated URL, where the change can be acted upon.

To facilitate this communication, you have to be subscribed to the changes, as explained in the API guide. I was playing around with the API last couple of days, so the first thing I wrote was a simple subscription manager in PHP.

Here are some examples:
Subscribe to 'feed':
php facebook_realtime_register.php -i [app_id] -s [app_secret] -c http://myapp.com/callback/ -t [verify_token] -a post -f feed

List active subscriptions:
php facebook_realtime_register.php -i [app_id] -s [app_secret] -a get

"data": [
"object": "user",
"callback_url": "http://myapp.com/callback/",
"fields": [
"active": true

As it is now, I think the API is lacking. The biggest problem in my opinion is that the actual notification does not contain an ID - so if my friends list changes I cannot be notified with ID's which changed, or if my feed changes I cannot easily get the ID's of new posts.

The other limitation are the actual fields which you can subscribe to - currently, the interesting fields like 'posts', 'photos', 'videos', etc cannot be subscribed to.

Promising, but boring for now!


  1. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
    SEO tools