TheRealAgentK/facebook-cf-sdk

OAuthException - Code was invalid or expired. The session is invalid because the user logged out.

Closed this issue · 4 comments

I've just tried a new v3.1.1-beta2 example (http://affinitiz.com/facebook-cf-sdk/examples/website/)

I went to the example logged and granted permission, worked fine. Then go outside the example and logged out from FB, backed to the example refreshed the webpage and...

Sorry, an error occurred.
It has been automatically recorded for further correction.

The installed example on my localhost gives me error report:

OAuthException - Code was invalid or expired. The session is invalid because the user logged out.

The error occurred in C:\ColdFusion9\wwwroot\LEProject_alpha\facebook\sdk\FacebookBase.cfc: line 75
Called from C:\ColdFusion9\wwwroot\LEProject_alpha\facebook\sdk\FacebookGraphAPI.cfc: line 256
Called from C:\ColdFusion9\wwwroot\LEProject_alpha\facebook\sdk\FacebookApp.cfc: line 438
Called from C:\ColdFusion9\wwwroot\LEProject_alpha\facebook\sdk\FacebookApp.cfc: line 254
Called from C:\ColdFusion9\wwwroot\LEProject_alpha\header.cfm: line 23
Called from C:\ColdFusion9\wwwroot\LEProject_alpha\index.cfm: line 1
73 : }
74 : }
75 : throw(errorCode="#exception.getErrorCode()#", message="#exception.getType()# - #exception.getMessage()#", type="#exception.getType()#");
76 : }
77 : } else if (isSimpleValue(response.fileContent) && response.statusCode == "200 OK") {

To go out of the error I have to remove cookies from the browser.

Indeed, there was an issue. I've fix the bug in the FacebookApp.getUserAccessToken method.
I've just pushed v3.1.1-beta4, which includes those changes.

Thank you for you feedback!

Hi Benoit, I have the latest version (3.1.1 b4) and am having a similar issue. Mine is a case of the session timing out, I'm sure... the cookie still exists but FB times out the auth token and it seems I'm left with this error to handle. I still have the FB member ID (#userid#) available to the system but the callAPIService() function throws the "Code was invalid or expired. Session has expired at unix time 1318244400. The current unix time is 1318263279." error and I'm not sure how I should be handling this. I would have figured the invalidateUser() would have taken care of this and while the code is clean and easily modified I don't want to start playing around when you are so active in development. Am I missing something?

The invalidateUser should be automatically called in that case, but an error is still thrown for the SDK.
This is normal.

You should always put API calls inside try/catch blocks to catch errors and see if you can ignore them or not.
For example, if the error type is an expired session then you can ignore it.