用facebook登录突然停止工作 [英] Login with facebook suddenly stopped working

查看:83
本文介绍了用facebook登录突然停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

突然在我的Web应用程序中使用Facebook登录停止工作.

Suddenly login with facebook in my web application stopped working.

以下是我的网站登录页面的代码.我使用的是Facebook php sdk,它可以正常工作到5个小时,现在它停止了.

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.

我很困惑,想知道到底发生了什么,因为自最近5个小时以来我一直无法解决它.我删除了连接数据库和查询代码的php代码,使其看起来很简单.

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.

我只接受两个范围,即email和publish_stream

I take only two scopes that is email and publish_stream

以下代码的输出为您好,您的fb用户ID为

<?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
} 
?>

推荐答案

FB令牌的有效期仅2小时.来自FB文档...

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

检索Facebook访问令牌时,相关的到期时间 通常也会返回带有访问令牌的访问令牌.如果这个到期 时间已过,您的应用程序将需要获得新的访问权限 令牌(还将具有一个与之关联的新的到期时间).

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).

但是您可以交换令牌并获得一个新的令牌,该令牌的有效期为60天.

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()
                )

有关此内容的更多信息,请参见 here

More information regarding this can be found here

这篇关于用facebook登录突然停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆