You are here

function facebook_get_access_token in Facebook Connect 7.2

Same name and namespace in other branches
  1. 8.2 fbconnect.module \facebook_get_access_token()

Get the Facebook access token object for easy access.

1 call to facebook_get_access_token()
facebook_client_session in ./fbconnect.module
Get the Facebook client object for easy access.

File

./fbconnect.module, line 149
Facebook Connect API module.

Code

function facebook_get_access_token() {
  static $token = NULL;
  $conf = fbconnect_get_config();
  if (!empty($_SESSION['fbconnect_token'])) {
    $token = $_SESSION['fbconnect_token'];
  }
  elseif (!empty($_COOKIE['fbconnect_token_' . $conf['app_id']])) {
    $_SESSION['fbconnect_token'] = $_COOKIE['fbconnect_token_' . $conf['app_id']];
    $token = $_SESSION['fbconnect_token'];
  }
  elseif (empty($token)) {
    $redirect_url = url('fbconnect/authorize', array(
      'absolute' => TRUE,
      'query' => array(
        'token' => NULL,
      ),
    ));
    $helper = new FacebookRedirectLoginHelper($redirect_url, $conf['app_id'], $conf['secret_api_key']);
    try {
      $session = $helper
        ->getSessionFromRedirect();
      if ($session) {
        $_SESSION['fbconnect_token'] = (string) $session
          ->getAccessToken();
        $token = $_SESSION['fbconnect_token'];
      }
    } catch (\Exception $e) {
    }
  }
  return $token;
}