You are here

function fbconnect_get_fbuid in Facebook Connect 8.2

Same name and namespace in other branches
  1. 5 fbconnect.module \fbconnect_get_fbuid()
  2. 6.2 fbconnect.module \fbconnect_get_fbuid()
  3. 6 fbconnect.module \fbconnect_get_fbuid()
  4. 7.2 fbconnect.module \fbconnect_get_fbuid()

Check Facebook session.

Parameters

boolean $check_connected: ensure that active user is connected with active Facebook account

Return value

integer Facebook user id

11 calls to fbconnect_get_fbuid()
fbconnect_fbapp_settings in ./fbconnect.admin.inc
fbconnect_fbapp_settings_submit in ./fbconnect.admin.inc
fbconnect_get_user_info in ./fbconnect.module
Query information from Facebook user table.
fbconnect_invite_block_view in fbconnect_invite/fbconnect_invite.module
Implements hook_block_view().
fbconnect_login_autoconnect_form_submit in fbconnect_login/fbconnect_login.module
Submit handler for autoconnect form.

... See full list

File

./fbconnect.module, line 213
@todo.

Code

function fbconnect_get_fbuid($check_connected = FALSE) {
  global $user;
  $fbuid = 0;
  $fb = facebook_client();
  if ($fb && ($request = $fb
    ->request('GET', '/me', array(), facebook_get_access_token()))) {
    try {
      $client = $fb
        ->getClient();
      $response = $client
        ->sendRequest($request);
      $fbuid = $response
        ->getGraphUser()
        ->getId();
      if (module_exists('fbconnect_login') && $check_connected && $fbuid) {
        if (_get_user_fbuid($user->uid) != $fbuid) {
          $fbuid = NULL;
        }
      }
    } catch (Exception $e) {
      $fbuid = 0;
    }
  }
  return $fbuid;
}