Reputation: 239
In my web application user log in with their email id, connect user's Facebook account, the post status on facebook, and log off from website ( to disconnect Facebook account from website has option "disconnect"), when the user re-login to the website at that time already connected user‘s Facebook account should be in connected state , i.e. user no need to again connect Facebook account.
if ( isset( $session )) {
$session = new FacebookSession( $session->getToken() );
$_SESSION['fb_token'] = $session->getToken();
$session = new FacebookSession( $session->getToken() );
$request = ( new FacebookRequest( $session, 'GET', '/me' ) )->execute();
$user = $request->getGraphObject()->asArray();
$_SESSION['fb']=$id=$user['id'];
$_SESSION['fb_username']=$user['name'];
$logoutURL = $helper->getLogoutUrl( $session, 'https://sharebulk.com/profile/disconnect.php' );?>
<div class="col-sm-5 " >
<div style=" margin-left: 20%;" >
<img src="../images/facebook-icon.png" height="51px" width="69px">
</div >
<p>
<a href="<?php echo $logoutURL ;?>" class="btn btn-xlarge btn-facebook ">DisConnect </a>
</p>
</div>
<?php } else {
$loginUrl = $helper->getReRequestUrl(["public_profile", "user_managed_groups","publish_actions","email","user_posts","user_photos",
"publish_pages", "manage_pages","user_birthday","user_status","read_stream"]);?>
<div class="col-sm-5 " >
<div style=" margin-left: 20%;" >
<img src="../images/facebook-icon.png" height="51px" width="69px">
</div >
<p>
<a href="<?php echo $loginUrl ;?>" class="btn btn-xlarge btn-facebook ">Connect Facebook</a>
</p>
</div>
<?php } ?>
In logout.php :-
<?php
session_start();
unset( $_SESSION['uid']);
header('Location:index');
?>
Here $_SESSION['uid'] is email id from which user login(Login with email).
How can i manage Facebook session so if user is logout from my web app and if user again login then Facebook session should be there until user is disconnect form dashboard.I am using PHP .
Thanks
Upvotes: 3
Views: 758
Reputation: 755
Are you looking for Long Lived session, You can save Long lived session to you database and when user connects back, you could use the same long lived session to connect him back to facebook.. I hope these links will help you
Upvotes: 1