Facebook PHP SDK v4 Redirect when already logged

蓝咒 提交于 2020-01-25 10:25:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!