2

I'm currently developing an app in facebook which has a list of friends of the user logged in and shows their online presence. To get this, I used the following FQL query:

SELECT name,uid, online_presence FROM user WHERE online_presence IN ('active', 'idle') AND uid IN ( SELECT uid2 FROM friend WHERE uid1 = me())

friends_online_presence is an extended permission and returns the Facebook Chat status (a string, one of active, idle, offline or error).

My question is how can I get a real-time update of online-presence change by my friends?

Option 1: Query the Facebook API periodically, in a background process
Option 2: Hook into XMPP to get real-time updates ( an answer from duplicate question below).

People have asked this question before here too, here are some duplicates(unsolved):
facebook-api-real-time-friends-online-presence-update &
Is-it-possible-to-subscribe-to-real-time-updates-for-user-online-presence.

I wanted to know if someone has solved the problem and if yes, how did you solve it.

It'd be great if you could elaborate a bit about the Option 2 (using XMPP/Jabber), because I feel periodically querying would suffice for only a while, when the user count is less.

Community
  • 1
  • 1
Jatin Ganhotra
  • 6,825
  • 6
  • 48
  • 71

1 Answers1

3

The best way is to use XMPP.

For integrating facebook chat via XMPP, I think the best way in Rails would be

  1. Rails + StropheJS
  2. In addition to this, you could include something like ember.js (but that's not a necessity)

Overall, the system would look like

StropheJS (client side JS) ----> XMPP BOSH Manager (eJabberd / Punjab) ----> Facebook Servers

In addition to all this, if you are new to XMPP then the book "Professional XMPP Programming with JavaScript and jQuery" is worth a read and has lots of examples with strophejs

Nishant
  • 2,975
  • 23
  • 38
  • Thanks for your reply, but your answer doesn't really get me anywhere. Can you explain in detail, may be list down some steps that'll get my job done quick. – Jatin Ganhotra Jan 14 '13 at 15:47
  • @JatinGanhotra Here is a blog post, which talks about setting up this (with the ruby gem xmpp4r) http://siddharth-ravichandran.com/2011/01/21/multiuser-chat-using-xmpp-and-orbited-using-ruby-on-rails/ . I plan to write down all the steps necessary, but that would take time. Will update the answer soon. Also check if this helps http://www.slideshare.net/ca168168/realtime-webwithrailsxmpp – Nishant Jan 14 '13 at 16:19
  • Thanks for your quick reply. I'll start off with this, and wait for your updated answer meanwhile. – Jatin Ganhotra Jan 14 '13 at 16:41
  • I'm giving my bounty rep to you, will be waiting for your updated answer and any help possible. Since yours is the only answer, if I don't award it to you, my bounty rep would be lost, not doing any of us good. :) – Jatin Ganhotra Jan 14 '13 at 16:45
  • @JatinGanhotra :) Thanks. Plan to do it soon. – Nishant Jan 14 '13 at 16:47
  • @Nishant Per my question here (stackoverflow.com/questions/27222641/…) I heard from Facebook directly that you can't currently subscribe to online_presence and they have no plans to make that possible. Do you think there's a different way to use XMPP to get this info? – user1544138 Dec 14 '14 at 02:37