[英]Facebook PHP SDK Long-lived access token expires after refresh site
我正在使用Facebook SDK v5 for PHP,并且试图获取长期存在的USER访问令牌。
我得到了它,使其寿命长了一次并保存到我的数据库中,然后我转到另一个页面,在其中使用它来获取对Facebook PAGE的访问令牌。 至此,一切正常。 然后刷新页面,User AccessToken的[“ expiry at”]设置为1970-01-01。
我不知道发生了什么,因为我没有在数据库中重写此访问令牌。 最重要的是,此令牌可与facebook一起使用。 因此,刷新前后都有我的代码和响应。
$config = array();
$config['app_id'] = xxx
$config['app_secret'] = xxx
$config['fileUpload'] = false;
if(!empty(tokenFromDatabse)){
$config['default_access_token'] = tokenFromDatabse;
}
$fb = new Facebook($config);
$oAuth2Client = $fb->getOAuth2Client();
if(!empty(tokenFromDatabse)){
try{
$tokenMetadata = $oAuth2Client->debugToken($fb->getDefaultAccessToken());
$tokenMetadata->validateAppId($config['app_id']);
$tokenMetadata->validateExpiration();
}
这只是动作的全部内容,当然还有捕获代码。 现在,facebook的第一反应是:
object(Facebook\Authentication\AccessTokenMetadata)#689 (1) {
["metadata":protected]=>
array(7) {
["app_id"]=>
string(15) "xxx"
["application"]=>
string(13) "Local_app"
["expires_at"]=>
object(DateTime)#691 (3) {
["date"]=>
string(26) "2015-10-20 16:07:56.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
["is_valid"]=>
bool(true)
["issued_at"]=>
object(DateTime)#692 (3) {
["date"]=>
string(26) "2015-08-21 16:07:56.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
["scopes"]=>
array(3) {
[0]=>
string(12) "manage_pages"
[1]=>
string(13) "publish_pages"
[2]=>
string(14) "public_profile"
}
["user_id"]=>
string(15) "xxx"
}
刷新后看起来像这样:
object(Facebook\Authentication\AccessTokenMetadata)#689 (1) {
["metadata":protected]=>
array(7) {
["app_id"]=>
string(15) "xxx"
["application"]=>
string(13) "Local_app"
["expires_at"]=>
object(DateTime)#691 (3) {
["date"]=>
string(26) "1970-01-01 01:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
["is_valid"]=>
bool(true)
["issued_at"]=>
object(DateTime)#692 (3) {
["date"]=>
string(26) "2015-08-21 16:07:56.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
["scopes"]=>
array(3) {
[0]=>
string(12) "manage_pages"
[1]=>
string(13) "publish_pages"
[2]=>
string(14) "public_profile"
}
["user_id"]=>
string(15) "xxx"
}
扩展页面访问令牌根本没有任何默认到期时间。 并且由于实现细节,用于请求扩展页面访问令牌的用户访问令牌也“无限期”变为有效。
因此,到期值将为0,null或类似的值。 并且当格式化为日期时,它将变为1970-01-01,因为那是unix时代的开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.