Fetch Online Friends List With Facebook Graph Api
Sep 29th, 2011This article is a step-by-step PHP tutorial explaining how to use the Facebook PHP SDK to get the list of the online friends of the current user.
To get the list of online friends in PHP, first you need to authenticate users with their Facebook account asking for the permission friends_online_presence
. This is done using the Facebook PHP SDK (see on github) adding friends_online_presence
to the scope while generating the login link:
Then, if the user is logged in, you can make the request:
The results will be like:
Array(
[0] => Array(
[uid] => 1536397056
[name] => Quentin Pleplé
[pic_square] => http://...jpg
[online_presence] => active
)
[1] => ...
[2] => ...
...
)
The online_presence
property can take 4 values: active
, idle
,
offline
, or error
.