You are here

function fb_users_getInfo in Drupal for Facebook 7.3

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

DEPRECATED. Use fb_api() instead. Returns information about one or more facebook users.

Historically, this helper function used facebook's users_getInfo API, hence the name. Now it uses fql.query, but accomplishes the same thing.

Parameters

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

$fb: Rarely needed. For cases when global $_fb is not set, or more than one facebook api has been initialized.

$refresh_cache: If true, force a call to facebook instead of relying on temporarily stored data.

5 calls to fb_users_getInfo()
fb_devel_fbu_page in ./fb_devel.module
A page which tests function which work with facebook user ids
fb_form_friend_selector_value in ./fb_form.module
Convert #default_value into a value for the form field
fb_user_app_get_proxied_email in contrib/fb_user_app.module
Learn the user's proxied email address.
fb_user_create_local_user in ./fb_user.module
Creates a local Drupal account for the specified facebook user id.
fb_user_get_proxied_email in ./fb_user.module
Learn the user's proxied email address. If fb_user_app.module is enabled, it will defer to that module, which queries a local database. If not, ask facebook for the data.

File

./fb.module, line 1758
This is the core required module of Drupal for Facebook.

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) {
    $app_id = $fb
      ->getAppId();

    // First try cache
    if (!$refresh_cache && isset($_SESSION['fb'])) {
      foreach ($oids as $oid) {
        if (isset($_SESSION['fb'][$app_id]['userinfo'][$oid])) {
          $info = $_SESSION['fb'][$app_id]['userinfo'][$oid];
          $infos[] = $info;
        }
      }
    }
    if (count($infos) != count($oids)) {

      // Session cache did not include all users, update the cache.
      $fields = array(
        'about_me',
        'affiliations',
        'birthday',
        'name',
        'first_name',
        'last_name',
        'is_app_user',
        'pic',
        'pic_big',
        'pic_square',
        'profile_update_time',
        'proxied_email',
        'email_hashes',
        'email',
        'uid',
      );
      try {
        $infos = fb_fql_query($fb, 'SELECT ' . implode(', ', $fields) . ' FROM user WHERE uid in(' . implode(', ', $oids) . ')', array(
          fb_get_token($fb),
        ));

        // Update cache with recent results.
        if (is_array($infos)) {
          foreach ($infos as $info) {
            $_SESSION['fb'][$app_id]['userinfo'][$info['uid']] = $info;
          }
        }
      } catch (FacebookApiException $e) {
        fb_log_exception($e, t('Failed to query facebook user info'), $fb);
      }
    }
    return $infos;
  }
}