I am using the PHP SDK on my website. I have developed a registration form and login form.
The facebook login link is generated, the user clicks and authorises the app. They are redirected to my site and have an access token.
I can use API call such as $this->facebook->api('/me/'); I put the call within a try statement and catch any exceptions.
It works perfectly.
The problem is that randomly my access token will expire, as such the api all cannot complete and the exception is caught. I don't know why this is, but what i want to do is seamlessly refresh the access token.. i.e get a new one and continue the users session on the site seamlessly.
What i thus do is save their location in a session, redirect the user to the facebook login page in the catch statement, and then on successfully re-logging in the user redirecting back to where they were.
This works, but there is a problem. Having this:
try
{
$me = $CI->facebook->api('/me');
}
catch(FacebookApiException $e)
{
//redirect to fb login lin
}
on every page essentially doubles the page load time of every page on the site - the Facebook PHP SDK is inherently slow.
Instead of 1 second page loads, they are taking 2-3 seconds. I have benchmarked it, and it is because of this try/catch..
What can i do? HOw can i maintain/refresh an access key for an authorised user without huge load time costs to my users?