Implementing Facebook Real-time updates API (with CURL examples)
I recently implemented Facebook’s real-time updates api. Since I couldn’t find a decent tutorial and ran into a few small roadblocks, I thought I’d share what I learnt.
This tutorial basically gets real-time updates of any name changes for users of your FB app. I’m going to use examples with Curl – since that’s like the swiss knife of http programming.
Step 1 – get access token
Note you can also use your api key (which I accidentally did!)
This should return a 40 over character long access token, the initial part looks suspiciously like your app id e.g.
Step 2 – Check if access token is working (optional)
With access token in hand, you can now query what real-time updates your app is already subscribed to. Real-time updates API is RESTful; so a HTTP Get returns your current subscriptions. e.g.
curl "https://graph.facebook.com/<appid>/subscriptions?access_token=<access token from step (1)>"
This result is JSON-encoded. If you’re just starting out, you would have no subscriptions:
If you somehow goofed up, a JSON-encoded error is returned:
Note: api key can’t be used instead of app id here!
Step 3 – Submit your update
This is the meat of the call. You are to submit a HTTP POST with Form-like arguments (don’t POST with JSON-encoded arguments as I had wrongly assumed)
curl -F 'object=user' \ -F 'callback_url=<callback url you have to implement>' \ -F 'fields=name' \ -F 'verify_token=<secret token>' \ "https://graph.facebook.com/<appid>/subscriptions?access_token=<access token from (1)"
curl should return “null”. Go back to Step (2) to check if all you entered was recorded by Facebook.
Hope this helps!