Jump to content
Killersites Forums

Facebook Connect Token Problem


Recommended Posts

Hello everyone, i am working on a website that uses facebook api to login with facebook.


However i am having a problem with the Javascript and PHP sdk.


The problem is that i keep getting an unexpected error which basically expires the facebook Auth Token and then it logs the user out of the website then logs them back in.



The code that i am using is below....



require 'facebook.php';

$facebook = new Facebook(array(
 'appId'  => 'MY_APP_ID_HERE',
 'secret' => 'MY_APP_SECRET',
 'cookie' => true

// See if there is a user from a cookie
$user = $facebook->getUser();

if ($user) {
 try {
   // Proceed knowing you have a logged in user who's authenticated.
   $user_profile = $facebook->api('/me');
 } catch (FacebookApiException $e) {
   echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
   $user = null;

<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
   <?php if ($user) { ?>
     Your user profile is
       <?php print htmlspecialchars(print_r($user_profile, true)) ?>
   <?php } else { ?>


   <?php } ?>
   <div id="fb-root"></div>
     window.fbAsyncInit = function() {
         appId: '<?php echo $facebook->getAppID() ?>',
         cookie: true,
         xfbml: true,
         oauth: true
       FB.Event.subscribe('auth.login', function(response) {
       FB.Event.subscribe('auth.logout', function(response) {
     (function() {
       var e = document.createElement('script'); e.async = true;
       e.src = document.location.protocol +




The error that i get when the user logs out is this:


[error] => Array
                                           [message] => An active access token must be used to query information about the current user.
                                           [type] => OAuthException
                                           [code] => 2500




Can someone please tell me if i am doing something wrong?


How can i get the session to NOT expire so fast?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...