You used to be able to do this with the Facebook Query Language (FQL) that Facebook exposed, sending something like this query to the FQL endpoint.
SELECT uid, name, online_presence
FROM user
WHERE online_presence IN ('active', 'idle')
AND uid IN (
SELECT uid2 FROM friend WHERE uid1 = me()
)
Unfortunately, the current version of the Facebook Graph API[0] doesn't have the online_presence field, so this is no longer possible. Maybe the Graph API will be updated in the future to also return the online_presence fields?[0] https://developers.facebook.com/docs/graph-api/reference/v2....