yii-facebook-opengraph and access token


I have a curious problem with the aforementioned extension. Whenever I log in with facebook, and come to the specified redirection page, I have no access token in the session and the usual techniques of checking fb auth fail, e.g. the Login Link is displayed instead of the logout link (I have code and state in the url). When I refresh the page or go to another page, I have the access token, and am considered logged in. I have extracted the following error message: Code_was_invalid_or_expired__The_session_is_invalid_because_the_user_logged_out.

This happens in the function getAccessTokenfromCode. However, this message is thrown internally whenever FB is checking if there is an auth user. I guess something is out of sync, or comes too late, but I wonder what?

The code is very simple, hence why I am really puzzled:


	$user = Yii::app()->facebook->getUser();

	if ($user) {

	  try {

	    // Proceed knowing you have a logged in user who's authenticated.

	    $user_profile = Yii::app()->facebook->api('/me');

	  } catch (FacebookApiException $e) {

	  	//throw $e;

	    $user = null;



// Login or logout url will be needed depending on current user state.

if ($user) {

  $logout_url = Yii::app()->facebook->getLogoutUrl();

  echo CHtml::link('Log out from Facebook', $logout_url); 

} else {

  $login_url = Yii::app()->facebook->getLoginUrl();

  echo CHtml::link('Log in with Facebook', $login_url);