You are here

function simple_fb_connect_save_session in Simple FB Connect 7.2

Checks that we have a valid FB session after Facebook has returned the user back to our site. User's access token is saved to $_SESSION.

Parameters

FacebookRedirectLoginHelper $login_helper: FacebookRedirectLoginHelper object.

Return value

FacebookSession object if we have a valid FB session, FALSE otherwise.

1 call to simple_fb_connect_save_session()
simple_fb_connect_return_from_fb in ./simple_fb_connect.module
Page callback for /user/simple-fb-connect/return.

File

./simple_fb_connect.module, line 330
Simple Facebook Login Module for Drupal Sites.

Code

function simple_fb_connect_save_session(FacebookRedirectLoginHelper $login_helper) {
  try {
    $fb_session = $login_helper
      ->getSessionFromRedirect();
    if ($fb_session) {

      // Store user access token to $_SESSION.
      $_SESSION['simple_fb_connect']['user_token'] = $fb_session
        ->getToken();
      return TRUE;
    }
    else {

      // If the user cancels the dialog or return URL is invalid,
      // Facebook will not throw an exception but will return NULL.
      watchdog('simple_fb_connect', 'Could not start FB session. User cancelled the dialog in FB or return URL was not valid.', array(), WATCHDOG_ERROR);
    }
  } catch (FacebookRequestException $ex) {

    // When Facebook returns an error.
    watchdog('simple_fb_connect', 'Could not save FB session. FacebookRequestException: @message', array(
      '@message' => json_encode($ex
        ->getResponse()),
    ), WATCHDOG_ERROR);
  } catch (\Exception $ex) {

    // When validation fails or other local issues.
    watchdog('simple_fb_connect', 'Could not save FB session. Exception: @message', array(
      '@message' => $ex
        ->getMessage(),
    ), WATCHDOG_ERROR);
  }
  return FALSE;
}