I always get the same error, if an user is registering for the first time:

"{"error":{"message":"Code was invalid or expired. Session is invalid. This could be because the application was uninstalled after the session was created.","type":"OAuthException","code":100}}"

After reloading the current page or at the next login with facebook, everything is working fine.

Comments

relaxy’s picture

Facebook access code generation seems to take a lot of time. A possible workaround for this problem could be:

function fboauth_access_token($code, $action_name, $app_id = NULL, $app_secret = NULL) {

...

// Give Facebook the time it needs.
sleep(3);
$authentication_result = drupal_http_request($token_url);

...

}
relaxy’s picture

A slightly better approach:


function fboauth_access_token($code, $action_name, $app_id = NULL, $app_secret = NULL) {

...

  $attempts = 5; 
  do {	  
	  $authentication_result = drupal_http_request($token_url);	   
	  if ($authentication_result->code == 200) {
	  	break;
	  }    
      // Facebook access code generation seems to take a lot of time. That's why we have to wait
      // some seconds before the code can be acquired.
      sleep(1);     
  }while(--$attempts > 0);

...

}

relaxy’s picture

Component: Miscellaneous » Code
quicksketch’s picture

Title: Registration failure » Access token failure when Facebook is responding slowly
Status: Active » Needs review

Interesting, I've never encountered this problem. I would think that Facebook would not return you a secret key until after it was ready to receive the response. The API is designed to immediately be queried for an access token after a secret key is provided, so I'm surprised we'd need to give Facebook time to accept the secret it just provided to us.

I'm supposing you've tried this solution and it has been successful, fixing the problem you encountered?

relaxy’s picture

The problem was already discussed at: http://developers.facebook.com/bugs/419168608133421?browse=search_50eded...

I've tried the mentioned solution and it's working fine. The downside of this approach is a longer delay in case of the real error, cause the break; would never be triggered.