Is there a way to determine whether a Facebook app user is actually online and using my FB app or not?
I am working on my first Facebook app.
It involves messaging users as a game progresses at various stages.
I wish to make the notifications on the page instead of routing them through Facebook requests IF the user happens to be online and using my app already, otherwise I will use FB requests as is documented.
Has anyone else tried to do this?
Are there any examples which anyone can reference?
I am prepared to restrict the app to HTML5 users at this point if it makes it easier!
Finding out if a user is a user of your app is easy – the Graph API user object has the installed field, and the FQL user table has a column is_app_user, which both provide you with that info.
Checking if another user of your app is “online” is harder, though. The FQL user table has a column online_presence, but that contains only “the user's Facebook Chat status” – so I guess that has not enough significance to base the decision “is user online in my app” upon.
Your alternative to that is implement it yourself – in the same way that those “8154 people are online right now” displays on community websites work: Whenever the user takes any action in your app, you save his user id and the current timestamp to your database – and everyone for whom this last action timestamp is no older than x seconds is considered “online”. Of course this is also little more but an “educated guess”, so you should check if your message to an “online” user actually could get delivered, and if it’s not after a certain time, then send it as an app-to-user request again.