Facebook PHP SDK长期访问令牌在刷新站点后过期


Facebook PHP SDK Long-lived access token expires after refresh site

我正在使用Facebook SDK v5 for PHP,我试图获得长期用户访问令牌。
我得到它,使长寿命一次,并保存到我的数据库,然后我去另一个页面,我用它来访问Facebook页面。到目前为止,一切都很顺利。然后刷新页面,用户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();
                }

这就是所有动作的作用,当然还有catch代码。现在,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纪元的开始。