You are here

function fbconnect_get_connected_friends in Facebook Connect 6.2

Same name and namespace in other branches
  1. 8.2 fbconnect_invite/fbconnect_invite.module \fbconnect_get_connected_friends()
  2. 5 fbconnect.module \fbconnect_get_connected_friends()
  3. 6 fbconnect.module \fbconnect_get_connected_friends()
  4. 7.2 fbconnect_invite/fbconnect_invite.module \fbconnect_get_connected_friends()

Get facebook friend who has_added_app.

1 call to fbconnect_get_connected_friends()
fbconnect_invite_block in fbconnect_invite/fbconnect_invite.module
Implements hook_block().

File

fbconnect_invite/fbconnect_invite.module, line 168
@todo.

Code

function fbconnect_get_connected_friends($fbuid) {
  if (fbconnect_facebook_client()) {
    $query = "SELECT uid, has_added_app FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = {$fbuid})";
    try {
      try {
        $rows = fbconnect_facebook_client()
          ->api(array(
          'method' => 'fql.query',
          'query' => $query,
        ));
      } catch (FacebookApiException $e) {
        drupal_set_message($e
          ->getMessage(), 'error');
        throw $e;
      }
    } catch (Exception $e) {
      $msg = 'Exception thrown while using fbconnect_get_connected_friends: @code';
      $args = array(
        '@code' => $e
          ->getMessage(),
      );
      watchdog('fbconnect', $msg, $args, WATCHDOG_ERROR);
    }
    if ($rows) {
      foreach ($rows as $row) {
        if ($row['has_added_app']) {
          $fbid[] = $row['uid'];
        }
      }
      if ($fbid) {
        $res = db_query('SELECT uid FROM {fbconnect_users} WHERE fbuid IN (' . implode($fbid, ',') . ')');
        while ($uid = db_result($res)) {
          $user = user_load($uid);
          if ($user->fb_visible) {
            $friends[] = $user;
          }
        }
        return $friends;
      }
    }
  }
}