Search code examples
phpfacebookauthenticationfacebook-php-sdkfacebook-oauth

Maintaining an active FB auth session for a website


I've found several questions that are sort of similar to mine, but not 100%.

I've got a site which has normal user accounts. You have the option of using FB auth as well. The problem is often when the user visits the page (sometimes even after a few hours) even though the users account cookie is still valid, their facebook session is not.

So the user appears to be logged in, (the webpage says "Hi, [user]") but I have no facebook session, and any facebook API call will fail until they re-click "login with facebook". -- This is all despite the fact that I'm still logged in to facebook.

Now, I did a similar implementation about 11-9 months ago, and the facebook session rarely ever expired. Now it seems to happen every few hours. Oddly, other websites which use facebook auth don't seem to be suffering from this problem.

Any idea what I can do to keep the facebook session alive for as long as possible? Thanks, Nick


Solution

  • Most people combine the php-sdk with the js-sdk. This looks for auth events and will usually trigger a reload of the page signing the user back in to facebook

    There's some sample code on the developer site, just above the following anchor

    https://developers.facebook.com/docs/guides/web/#insights