[英]Facebook API Login Error - Session has expired validating access token
I am logging Facebook login errors and sometimes I see this: 我正在记录Facebook登录错误,有时会看到以下信息:
OAuthException: Error validating access token:
Session has expired on Friday, 29-Apr-16 14:00:00 PDT.
The current time is Friday, 29-Apr-16 14:38:54 PDT.
What could be causing this? 是什么原因造成的? I assume someone went onto the website, the code got generated and then he clicked login 38 minutes later and the token was expired.
我假设有人上了网站,生成了代码,然后38分钟后他单击登录,令牌已过期。 How can I prevent this?
我该如何预防?
My code is like this: 我的代码是这样的:
$fbUser = $facebook->getUser();
if ($fbUser)
{
try
{
// We're logged in!
$user_profile = $facebook->api('/me');
}
catch (FacebookApiException $e)
{
// Oh no, an error :(
error_log($e);
$fbUser = null;
}
}
if ($fbUser)
{
try
{
$facebook_id = $facebook->getUser();
$facebook_me = $facebook->api('/me');
session->set('facebook_me', $facebook_me);
}
catch (FacebookApiException $e)
{
error_log($e);
}
}
else
{
$facebook_me = $session->value('facebook_me');
}
Please Used this code. This code is working in my web.
$fbconfig['appid' ] = "your_app_id";
$fbconfig['secret'] = "your_secret_key";
$fbconfig['baseurl'] = "your_redirect_url";
$user = null; //facebook user uid
// Create our Application instance.
$facebook = new Facebook(array('appId' => $fbconfig['appid'],'secret' => $fbconfig['secret'],'cookie' => true,));
//Facebook Authentication part
$user = $facebook->getUser();
// We may or may not have this data based
$loginUrl = $facebook->getLoginUrl (
array (
'scope' => 'email,user_birthday,user_location,user_work_history,user_about_me,user_hometown',
'redirect_uri' => $fbconfig['baseurl']
)
);
$logoutUrl = $facebook->getLogoutUrl();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me?fields=id,first_name,last_name,email,gender,locale,picture');
echo "<pre>";print_r($user_profile);die;
} catch (FacebookApiException $e) {
//you should use error_log($e); instead of printing the info on browser
d($e); // d is a debug function defined at the end of this file
$user = null;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.