2011年11月13日 星期日

[Facebook] Graph API - Real-time Update

The Graph API 提供 subscriptions API 訂閱資訊功能,讓 Application 能即時收到這些資訊的更新。

Here are the steps to set up a subscription:
  • Set up an endpoint URL that receives both HTTP GET (for subscription verification) and POST (for actual change data) requests from Facebook.
  • Make a POST to the graph API url https://graph.facebook.com/APPLICATION_ID/subscriptions to subscribe, and be ready to handle the verification request.
  • When data changes, and there is a valid subscription, Facebook servers will make an HTTP POST request to the callback_url you specified. 
  • The request will have content type of application/json; the body will be a JSON-encoded string containing one or more changes.
    • Note that this does not include the actual data values;
  •  Facebook aggregates changes and sends batched updates every 5 seconds or when number of unsent changes exceeds 1000, so your server(s) should be set up to handle this level of load.


You can currently subscribe to updates for these types of objects:
  • user
    • Get notifications about particular fields and connections corresponding to user nodes in the Graph API.
  • permissions (FQL)
    • Get notifications when your users change the permissions they afford your applications.
    • The fields are like those in the corresponding FQL table.
  • page
    • Get notifications when pages that have installed your application change their public properties. 
    • Note
      • Page topic is only used for subscribing to changes to public attributes of the page (like name, category, picture etc).
    • You can subscribe to the page's feed in the same way you subscribe to a user's feed - the subscription topic should be 'user' and the subscription field should be 'feed'


User connections to which you can/can't subscribe

  • Can
    • feed, friends, activities, interests, music, books, movies, television, likes, checkins
  • Can't
    • home, tagged, posts, photos, albums, videos, groups, notes, events, inbox, outbox, updates, accounts
  • Note
    • please check back on this page at later time for updates.



Questions
  • 即使 Facebook 會將更新資訊 post 到我們設定的 callback url,但怎麼將這資訊送到(push)手機上的 Application?
    • This service only for server-to-server communication.
    • 所以應再考慮若 app server 收到更新訊息,如何 push 到 app,can try C2DM.




* Reference
- Real-time Updates
- Subscription
- Facebook API 开发记录

- real-time Sample code
- [TLK]Q/A about real-time updates
- How to Implement Push Notifications for Android
- Does Android support near real time push notification

沒有留言:

張貼留言