auth_getSession() public method

Returns the session information available after current user logs in.
public auth_getSession ( string $auth_token ) : assoc
$auth_token string the token returned by auth_createToken or passed back to your callback_url.
return assoc array containing session_key, uid
 public function auth_getSession($auth_token)
 {
     $result = parent::auth_getSession($auth_token);
     // This will be used as the standard session key
     $this->setDefaultServer($this->servers['default'], $result['session_key']);
     return $result;
 }
if ($_REQUEST['logout']) {
    // clear the cookies
    setcookie('session_key');
    setcookie('uid');
} else {
    $session_key = $_COOKIE['session_key'];
    $uid = $_COOKIE['uid'];
}
if (!$auth_token && !$session_key) {
    header('Location: ' . $config['login_url']);
    return;
}
$client = new FacebookRestClient($config['rest_server_addr'], $config['api_key'], $config['secret'], $session_key, false);
if (!$session_key) {
    $expires = time() + 3600;
    $session_info = $client->auth_getSession($auth_token);
    $client->session_key = $session_info['session_key'];
    $uid = $session_info['uid'];
    /* You should not blindly trust cookies to provide valid authentication 
     * information since they are transmitted in the clear and can be easily 
     * modified (especially not for the user id).  We encourage you to use your 
     * own more advanced session management system, we merely do this as an 
     * example.  */
    setcookie('session_key', $session_info['session_key'], $expires);
    setcookie('uid', $uid, $expires);
}
$my_profile = $client->users_getInfo(array($uid), $profile_field_array);
$my_name = $my_profile[$uid]['name'];
$friends_array = array_slice($client->friends_get(), 0, 5);
$coworkers_array = $client->friends_getTyped('WORKED');
$albums = $client->photos_getAlbums($uid);
示例#3
0
$session_key = @$_SESSION['session_key'];
$uid = @$_SESSION['uid'];

$client = new FacebookRestClient($facebok_api_key, $facebook_api_secret);
//$client->server_addr = 'http://api.facebook.com/restserver.php';
$client->server_addr = 'http://pokemon.broadbandmechanics.com/fb_api/restserver.php';
//$client->debug = 1;
if ($session_key) $client->session_key = $session_key;

if (!$session_key) {
  $token = @$_GET['auth_token'];

  if ($token) {
    echo "<p>ok, i have an auth token: $token</p>";
    
      $r = $client->auth_getSession($token);
    
    $session_key = $_SESSION['session_key'] = $r['session_key'];
    $uid = $_SESSION['uid'] = $r['uid'];
  }
  else {

?>

<p><a href="http://api.facebook.com/login.php?api_key=<?php 
echo $facebook_api_key;
?>
" target="_blank">log in to facebook</a></p>


<form method="GET"><p>then paste the token from the url here: <input type="text" name="auth_token" size="20"><input type="submit" value="finish login"></p></form>