I have Facebook login database in my system. I am storing Long-Lived user access token with UserID to my database and I need to renew the token before it expires. I have found a page in Facebook API documentation and I tried to renew the token by following the steps. Facebook returns different access token, but expiration time is still the same.
This is what I've got: (I am using Facebook's PHPSDK 5.0.0)
$t = $this->access_token;
if ($t && $t->getExpiresAt()->getTimestamp() <= strtotime('+14 days'))
{
$oauth = $this->fb->getOAuth2Client();
$code = $oauth->getCodeFromLongLivedAccessToken($t, $this->redrect_urls['renew']);
$t = $oauth->getAccessTokenFromCode($code, $this->redrect_urls['renew']);
if ($t)
{
$this->database->table($this->config->getTable('facebook-logins'))
->where('user_id', $this->user_id)
->update(array(
'expires_at' => $t->getExpiresAt(),
'access_token' => $t->getValue(),
'facebook_name' => $this->getUserAccount()['name'],
));
}
}
What should I do to renew the token expiration date? Is it possible to do this token renewal fully automatically without bothering the user to click on link or whatever?
Thanks for any tips, TheKronnY