How to renew/extend facebook access tokens with PHP?

后端 未结 4 1884
失恋的感觉
失恋的感觉 2020-12-25 08:52

Facebook has removed the offline_access token functionality, now tokens have to be renewed whenever the user visits your website to keep them active.

Say someone has

4条回答
  •  囚心锁ツ
    2020-12-25 09:47

    use Facebook\FacebookSession;
    use Facebook\GraphSessionInfo;
    use Facebook\FacebookRequest;
    use Facebook\GraphUser;
    use Facebook\FacebookRequestException;
    use Facebook\FacebookRedirectLoginHelper;
    
        FacebookSession::setDefaultApplication('YOURAPPID', 'SECRET');
    
        $user_accessToken = $_COOKIE['access_token_facebook']
    
        $session = new FacebookSession($user_accessToken);
    
        try {
            $session->validate();
        } catch (FacebookRequestException $ex) {
            // When Facebook returns an error
            echo $ex->getMessage();
        } catch (\Exception $ex) {
            // When validation fails or other local issues
            echo $ex->getMessage();
        }
        if ($session) {
            // Exchange token for long token
            $longToken = $session->getExchangeToken();
            // ... your other stuff
        }
    

    Ref: https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens https://developers.facebook.com/docs/facebook-login/access-tokens#extending

提交回复
热议问题