dsfbnhc4373 2013-12-27 13:14
浏览 32

登录facebook突然停止工作

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
} 
?>
  • 写回答

1条回答 默认 最新

  • dongzou3751 2013-12-27 13:22
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?