5

First, I want to note that I do not want to request the offline_access extended permission. It's there for a reason but this isn't it.

I am creating an html5 app using the Facebook Javascript API. The user is on a single page for a long time playing the game. I get an access token at the beginning of the flow with FB.getLoginStatus but this token expires at some point and so I am then unable to query Facebook for the user.

I have tried calling FB.getLoginStatus again when the first token fails but this does not appear to be giving me a new access token.

Is the only way to reload the page? Kind of sucks because the user's state is disrupted.

Brad Dwyer
  • 6,305
  • 8
  • 48
  • 68

1 Answers1

4

FB.getLoginStatus will reauthenticate a user to your application and will give you a new access token to work with. You should be able to get the new token from response.authResponse.accessToken.

Are you receiving any particular error after the first token fails?

Jordan
  • 31,971
  • 6
  • 56
  • 67
  • Thanks Jordan. Is there any way to refresh this manually beforehand? Say once every 15 minutes? I have a setInterval that calls FB.getLoginStatus every few minutes but I think what must be happening is that the users are calling with the expired token before FB.getLoginStatus is called with the expired key. Being able to get a new one preemptively would be a big help. – Brad Dwyer Feb 18 '12 at 08:14
  • 1
    What your application should probably do is handle any exceptions by trying to reauthenticate with FB.getLoginStatus, rather than trying to preempt it. Logic would be: attempt FB interaction. If interaction succeeds, great. If interaction does not succeed, try FB.getLoginStatus() to reauthenticate, and then attempt FB interaction again. – Jordan Feb 18 '12 at 08:17