-2

Suddenly login with facebook in my web application stopped working.

The following is code of my login page for website. i am using facebook php sdk which was working fine till 5 hours back now it stopped.

I am confused and want to know what the hell happen to it as i am not able to solve it since last 5 hours. I have removed my php code connecting to database and query code to make it look simple.

I take only two scopes that is email and publish_stream

output of below code is hello your fb user id is

<?php 

require_once 'include/data.php'; 

//check to see if they're logged in 
if(isset($_SESSION['logged_in'])) { 
    header("Location: index.php"); 
}

$site_url = "http://example.com/facebook.php";  
require_once ('phpsdk/src/facebook.php');

// Create our application instance
$facebook = new Facebook(array(
  'appId'  => 'xxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'allowSignedRequest' => false
));

// Get User ID
$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) {
        error_log($e);
        $user = null;
    }
}

if($user){
    // Get logout URL
    $logoutUrl = $facebook->getLogoutUrl(array(
        'redirect_uri'  => 'http://example.com/logout.php',
        ));
}else{
    // Get login URL
    $loginUrl = $facebook->getLoginUrl(array(
        'scope'         => 'email, publish_stream',
        'redirect_uri'  => $site_url,
        ));
}

// checking

if(!$user) { 
    //echo "<a href='$loginUrl' >Login</a>"; 
    header("Location:$loginUrl");
} else { 
    // echo "<a href='$logoutUrl' >Logout</a><br />"; 
    $f_name = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $user_info['first_name']); 
    $l_name = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $user_info['last_name']); 
    $fb_email = $user_info['email']; 
    $fb_uid = $user_info['id']; 
    echo "hello your fb user id is $fb_uid"; // just sample to check
} 
?>
Popnoodles
  • 28,090
  • 2
  • 45
  • 53
Allison
  • 88
  • 1
  • 7

1 Answers1

0

The lifetime of the FB token is valid for just 2 hours. From the FB Docs...

When retrieving a Facebook access token, an expiration time associated with the access token is also typically returned. If this expiration time is exceeded, your application will need to obtain a new access token (which will also have a new expiration time associated with it).

However you can exchange the token and get a new one that has an extended validity say 60 days.. Something like this..

 $this->getUrl('graph', '/oauth/access_token'), array(
                    'client_id' => $this->getAppId(),
                    'client_secret' => $this->getAppSecret(),
                    'grant_type'=>'fb_exchange_token',
                    'fb_exchange_token'=>$this->getAccessToken()
                )

More information regarding this can be found here

Community
  • 1
  • 1
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • Its not matter of 2 hours **Critical Errors That Must Be Fixed** Facebook URL **Facebook URLs cannot be crawled.** i noticed this in debug – Allison Dec 27 '13 at 13:29