已登录的Facebook PHP SDK v4重定向 [英] Facebook PHP SDK v4 Redirect when already logged
问题描述
当用户已经登录时,是否可以获取会话?
Is there a way to get the session when the user is already logged in?
我只能做
$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');
我已经尝试过了
$session = new FacebookSession($_SESSION['FBRLH_state']);
但出现错误
Invalid OAuth access token.
推荐答案
您需要做的是将用户的access_token保存到会话或cookie中(例如,在fb_token
下).然后,通过检查是否设置了$ _SESSION ['fb_token']来查看cookie/会话是否存在.
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'] );
}
会话将根据您的设置而终止,因此使用$ _COOKIE可能会更好.
The session will expire depending on your settings, so using $_COOKIE might be better.
这篇关于已登录的Facebook PHP SDK v4重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!