Expired authorization code in PHP facebook SDK

I am using the new 4. * facebook php SDK and I have a problem !;)

Basically I am trying to find a way to make api schedule requests after the first redirect, when the user is sent back to my site after logging in to facebook . In this case, I (in mine index.php):

$h = FacebookRedirectLoginHelper("blablabla");
$request = new FacebookRequest($h->getSessionFromRedirect(), 'GET', '/me');
$me = $request->execute()->getGraphObject();

and it works great, and I can print the date of the registered user.

My problem is that if I reload the (f5) page index.php, I get an exception:

Fatal error: Uncaught exception 'Facebook\FacebookAuthorizationException' with message 'This authorization code has expired.' in /home/nourdine/development/faisbuk/vendor/facebook/php-sdk-v4/src/Facebook/FacebookRequestException.php:87 

So my question is: where should I get a new authorization code in order to create new graphical api calls with an authenticated user even on pages that are not executed as a result of the facebook login process?

thank

+4
2

. . $h->getSessionFromRedirect() . .

+3

, :

    // see if we have a session in $_Session[]
if( isset($_SESSION['token']))
{
    // We have a token, is it valid? 
    $session = new FacebookSession($_SESSION['token']); 
    try
    {
        $session->Validate($appid ,$secret);
    }
    catch( FacebookAuthorizationException $ex)
    {
        // Session is not valid any more, get a new one.
        $session ='';
    }
}

: Facebook SDK 4.0.0 PHP: .

+1

Source: https://habr.com/ru/post/1540052/


All Articles