You are here

function facebook_get_access_token in Facebook Connect 8.2

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

Get the Facebook access token object for easy access.

5 calls to facebook_get_access_token()
fbconnect_get_fbuid in ./fbconnect.module
Check Facebook session.
fbconnect_graph_query in ./fbconnect.module
Make Graph Query.
fbconnect_login_unregister in fbconnect_login/fbconnect_login.module
Unlink Facebook account from user account.
fbconnect_login_user_logout in fbconnect_login/fbconnect_login.module
Implements hook_user_logout().
fbconnect_user_profile in ./fbconnect.module
Get the user profile or return null if they are not logged in and registered.

File

./fbconnect.module, line 102
@todo.

Code

function facebook_get_access_token() {
  static $token = NULL;
  $facebook = facebook_client();
  $facebook_config = fbconnect_get_config();
  if (!empty($_SESSION['fbconnect_token'])) {
    $token = new AccessToken($_SESSION['fbconnect_token']);
  }
  elseif (!empty($_COOKIE['fbconnect_token_' . $facebook_config['app_id']])) {
    $_SESSION['fbconnect_token'] = $_COOKIE['fbconnect_token_' . $facebook_config['app_id']];
    $token = new AccessToken($_SESSION['fbconnect_token']);
  }
  elseif (is_null($token) && $facebook) {
    $helper = $facebook
      ->getJavaScriptHelper();
    try {
      $token = $helper
        ->getAccessToken();
    } catch (Exception $e) {
      $token = NULL;
    }
  }
  if (!empty($token)) {
    try {
      $request = $facebook
        ->request('GET', '/me', array(), $token);
      $response = $facebook
        ->getClient()
        ->sendRequest($request);
      $_SESSION['fbconnect_token'] = $token
        ->getValue();
    } catch (Exception $e) {
      $token = NULL;
      unset($_SESSION['fbconnect_token']);
      unset($_COOKIE['fbconnect_token_' . $facebook_config['app_id']]);
      setcookie('fbconnect_token_' . $facebook_config['app_id'], '');
    }
  }
  return $token;
}