问题
Is there a way to get the session when the user is already logged in?
I can only do
$session = $this->facebook->getSessionFromRedirect();
but I don't want the user to click the login link again.
Instead, when the user is already logged I just want to redirect and get the session to use
$request = new Facebook\FacebookRequest($session, 'GET', 'url');
I've tried this
$session = new FacebookSession($_SESSION['FBRLH_state']);
but I get an error
Invalid OAuth access token.
回答1:
What you need to do is save the user's access_token to the session or cookie (e.g. under fb_token
). Then, you can see if the cookie / session exists by checking if $_SESSION['fb_token'] is set.
if ( isset( $_SESSION['fb_token'] ) ) {
$session = new FacebookSession( $_SESSION['fb_token'] );
}
The session will expire depending on your settings, so using $_COOKIE might be better.
来源:https://stackoverflow.com/questions/25065627/facebook-php-sdk-v4-redirect-when-already-logged