简体   繁体   中英

How can I get a user's presence using Facebook php sdk?

I am using the latest PHP sdk for Facebook to grant my app permissions. This is how I granted the app permissions.

 $extra_params = array('scope' => 'email, read_mailbox,friends_online_presence,xmpp_login,publish_actions',
    );
    $loginUrl = $facebook->getLoginUrl($extra_params);

How can I get the users online alone? When I use the code below I get all users despite others being offline

$user_profile = $facebook->api('/me/friends');
    var_dump($user_profile);

and when I use this I get an empty array.

$user_profile = $facebook->api('/me/friends/online');
    var_dump($user_profile);

After a Google search I came across an fql that works fine. The code is below

    $params = array(
        'method' => 'fql.query',
        'query' => "SELECT uid,name,online_presence FROM user WHERE
  online_presence = 'active'
  AND uid IN (
    SELECT uid2 FROM friend where uid1 = me()
  )"
    );

        $user_profile = $facebook->api($params);
        var_dump($user_profile);

It works like charm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM