You are here

function fb_users_getInfo in Drupal for Facebook 5

Same name and namespace in other branches
  1. 5.2 fb.module \fb_users_getInfo()
  2. 6.3 fb.module \fb_users_getInfo()
  3. 6.2 fb.module \fb_users_getInfo()
  4. 7.3 fb.module \fb_users_getInfo()

Helper function for facebook's users_getInfo API.

This function makes calls to users_getInfo more efficient, by caching results in the session, so calls do not always require hitting Facebook's servers.

Particularly useful when displaying user info on canvas pages, where <fb:user> tags are not available.

Parameters

$oids: Array of facebook object IDs. In this case they should each be a user id.

File

./fb.module, line 622

Code

function fb_users_getInfo($oids, $fb = NULL) {
  if (!$fb) {
    $fb = $GLOBALS['fb'];
  }
  $infos = array();
  if ($fb) {

    // First try cache
    foreach ($oids as $oid) {
      if ($info = $_SESSION['fb'][$fb->api_key]['userinfo'][$oid]) {
        $infos[] = $info;
      }

      // else break
    }
    if (count($infos) != count($oids)) {

      // Session cache did not include all users, update the cache.
      $infos = $fb->api_client
        ->users_getInfo($oids, array(
        'about_me',
        'affiliations',
        'name',
        'is_app_user',
        'pic_big',
        'profile_update_time',
        'status',
      ));

      // Update cache with recent results.
      foreach ($infos as $info) {
        $_SESSION['fb'][$fb->api_key]['userinfo'][$info['uid']] = $info;
      }
    }
    return $infos;
  }
}