You are here

function fb_users_getInfo in Drupal for Facebook 5.2

Same name and namespace in other branches
  1. 5 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 iframe 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.

1 call to fb_users_getInfo()
fb_form_friend_selector_value in ./fb_form.module
Convert #default_value into a value for the form field

File

./fb.module, line 705

Code

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

    // First try cache
    if (!$refresh_cache) {
      foreach ($oids as $oid) {
        if ($info = $_SESSION['fb'][$fb->api_key]['userinfo'][$oid]) {
          $infos[] = $info;
        }
      }
    }
    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',
        'pic_big',
        'pic_square',
        'profile_update_time',
        'status',
      ));

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