user3260759
user3260759

Reputation: 513

Facebook PHP SDK v4 Redirect when already logged

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.

Upvotes: 0

Views: 598

Answers (1)

Niraj Shah
Niraj Shah

Reputation: 15457

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.

Upvotes: 1

Related Questions