FB SDK. The session is invalid because the user logged out

Asked
Active3 hr before
Viewed126 times

5 Answers

invalidsession
90%

You'll need a new access token. Hit this API:,https://graph.facebook.com/oauth/access_token?client_id=YOUR_ID&client_secret=YOUR_SECRET&grant_type=client_credentials, 1 You need to get a new access token. – CBroe Apr 28 '15 at 11:03 , https://graph.facebook.com/oauth/access_token?client_id=MYAPPID&client_secret=MYAPPSECRET&grant_type=fb_exchange_token&fb_exchange_token = $access _token I am generating long lived token by this, and once user user logout my session time out.. while i needed to access his wall post data although user offline. – Vishal Solanki Sep 1 '17 at 9:57

88%

The response of the API call is a JSON array that looks like this:,For long-lived access tokens the issued_at field is also returned.,Due to security related events, access tokens may be invalidated before the expected expiration time.,Replace {input-token} with the access token you want to get information about and {access-token} with a valid access token. The tokens must be from the same app.

To use the API, you can issue a Graph API request:

curl - i - X GET "https://graph.facebook.com/debug_token?
input_token = {
      input - token
   } &
   access_token = {
      valid - access - token
   }

The response of the API call is a JSON array that looks like this:

{
   "data": {
      "app_id": "{app-id}",
      "type": "USER",
      "application": "{app-name}",
      "data_access_expires_at": 1576687825,
      "expires_at": 1570820400,
      "is_valid": true,
      "scopes": [
         "pages_show_list",
         "public_profile"
      ],
      "granular_scopes": [{
         "scope": "pages_show_list",
         "target_ids": [
            "{page-1-app-can-access-id}",
            "{page-2-app-can-access-id}"
         ]
      }],
      "user_id": "10215241773831025"
   }
}
load more v
72%

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL), help? What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum About Us , communitylounge Who's Who Most Valuable Professionals The Lounge   The CodeProject Blog Where I Am: Member Photos The Insider News The Weird & The Wonderful ,What is 'CodeProject'?

65%

starting from a thinkdiff.net tutorial I have built a simple test page (local env) with a facebook login/logout link.If logged in i want to echo out the fb user API.,The problem is that the session cookie persists even after the user is logged out. When the user returns to your page you are trying to use that expired session to make requests. Good luck.,It seems to work but when i logout I receive this exception:,I would try manually clearing the session on logout. Put a GET parameter on the return url, or use a different return url, and then do this:

this is my test page code

$fbconfig['appid']  = "18196**********";     
$fbconfig['api']  = "5c6910be575e4e688ac6d**********";     
$fbconfig['secret']  = "a2fccb8e93638b50c8d6b2**********"; 

try
{         
   include_once "facebook.php"; 
}     
catch(Exception $o)
{         
 echo '<pre>';         
 print_r($o);         
 echo '</pre>';     
}     
// Create our Application instance.     
$facebook = new Facebook(array('appId'  => $fbconfig['appid'],'secret' =>    $fbconfig['secret'],'cookie' => true));       

$session = $facebook->getSession();       
$fbme = null;     
// Session based graph API call.     
if (!empty($session)) 
{       
  d($session);
  try 
  {         
    $uid = $facebook->getUser();         
    $fbme = $facebook->api('/me');       
  } 
  catch (FacebookApiException $e) 
  {           
    d($e);       
  }    
}      
function d($d)
{         
echo '<pre>';         
print_r($d);         
echo '</pre>';     
} 


if ($fbme) 
{   
  $logoutUrl = $facebook->getLogoutUrl(); 
  echo"<a href='{$logoutUrl}'>logout</a>";
  d($fbme);
} 
else 
{   
  $loginUrl = $facebook->getLoginUrl(array('req_perms' => 'email,read_stream,user_birthday')); 
  echo"<a href='{$loginUrl}'>login</a>";
}
load more v
75%

starting from a thinkdiff.net tutorial I have built a simple test page (local env) with a facebook login/logout link.If logged in i want to echo out the fb user API.,The problem is that the session cookie persists even after the user is logged out. When the user returns to your page you are trying to use that expired session to make requests. Good luck.,It seems to work but when i logout I receive this exception:,Update: As of Aug 2012 Facebook PHP-SDK have added simple way of extending access_token (see How to extend access token validity since offline_access deprecation for more details)

this is my test page code

$fbconfig['appid']  = "18196**********";     
$fbconfig['api']  = "5c6910be575e4e688ac6d**********";     
$fbconfig['secret']  = "a2fccb8e93638b50c8d6b2**********"; 

try
{         
   include_once "facebook.php"; 
}     
catch(Exception $o)
{         
 echo '<pre>';         
 print_r($o);         
 echo '</pre>';     
}     
// Create our Application instance.     
$facebook = new Facebook(array('appId'  => $fbconfig['appid'],'secret' =>    $fbconfig['secret'],'cookie' => true));       

$session = $facebook->getSession();       
$fbme = null;     
// Session based graph API call.     
if (!empty($session)) 
{       
  d($session);
  try 
  {         
    $uid = $facebook->getUser();         
    $fbme = $facebook->api('/me');       
  } 
  catch (FacebookApiException $e) 
  {           
    d($e);       
  }    
}      
function d($d)
{         
echo '<pre>';         
print_r($d);         
echo '</pre>';     
} 


if ($fbme) 
{   
  $logoutUrl = $facebook->getLogoutUrl(); 
  echo"<a href='{$logoutUrl}'>logout</a>";
  d($fbme);
} 
else 
{   
  $loginUrl = $facebook->getLoginUrl(array('req_perms' => 'email,read_stream,user_birthday')); 
  echo"<a href='{$loginUrl}'>login</a>";
}
load more v

Other "invalid-session" queries related to "FB SDK. The session is invalid because the user logged out"