Php 使用facebook登录突然停止工作
突然,在我的web应用程序中使用facebook登录停止工作 以下是我的网站登录页面的代码。我正在使用facebook php sdk,它在5小时前一直工作正常,现在它停止了 我很困惑,想知道到底发生了什么,因为我无法解决它,因为过去5个小时。我删除了连接到数据库的php代码和查询代码,使其看起来简单 我只使用两个作用域,即电子邮件和发布流 下面代码的输出是您好您的fb用户id是Php 使用facebook登录突然停止工作,php,facebook,facebook-graph-api,Php,Facebook,Facebook Graph Api,突然,在我的web应用程序中使用facebook登录停止工作 以下是我的网站登录页面的代码。我正在使用facebook php sdk,它在5小时前一直工作正常,现在它停止了 我很困惑,想知道到底发生了什么,因为我无法解决它,因为过去5个小时。我删除了连接到数据库的php代码和查询代码,使其看起来简单 我只使用两个作用域,即电子邮件和发布流 下面代码的输出是您好您的fb用户id是 <?php require_once 'include/data.php'; //check to s
<?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文档
在检索Facebook访问令牌时,与
通常还会返回访问令牌。如果到期
超过时间后,您的应用程序将需要获得新的访问权限
令牌(也将有一个新的过期时间与之关联)
但是,您可以交换代币并获得一个有效期延长的新代币,例如60天。。像这样的
$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()
)
有关这方面的更多信息,请参见我在6个月前遇到过这个问题,我认为问题在于facebook电子邮件,facebook没有返回用户的电子邮件地址,而是返回用户id,我将其更改为用户id并修复了问题我需要删除电子邮件吗?是的,我想是的,你需要匹配facebook用户id而不是Email是的,刚刚尝试过,但没有任何帮助。天哪!!!我重置了客户端令牌,它工作了。这不是2小时的问题,关键错误必须修复,Facebook URL无法爬网。我在调试中注意到了这一点