I'm using the Facebook PHP SDK to call relevant APIs to post and get data. At present I'm saving a user access token in the database but it expires after 60 days. How can I refresh a user access token?
1 . When do I need to refresh the access tokens? After it expires, or before?
2 . What is the best way to refresh access tokens?
3 . Should my users need to login again to refresh access token?
This is the function that I'm using to extend the access token. but expire time remain same.
public function getExtendedAccessToken($access_token)
{
$token_url="https://graph.facebook.com/oauth/access_token";
$params=array('client_id'=>self :: appId,'client_secret'=>self :: appSecretId,'grant_type'=>'fb_exchange_token','fb_exchange_token'=>$access_token);
$response = $this->curl($token_url,$params);
$response = explode ('=',$response);
$response = explode ('&',$response[1]);
$response = $response[0];
return $response;
}
The access token
can't be refreshed just like that, the user should access the app again to get the new token.
You can refresh the token at anytime you wish. In fact, the best way is to refresh the token each time the user visits your app. In this way, the token will never be expired if the user keep visiting the app once in 60 days.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With