Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to refresh facebook access token for server side (in facebook-php SDK)?

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;

    }
like image 362
Viral Solani Avatar asked Jul 26 '13 14:07

Viral Solani


1 Answers

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.

like image 80
Sahil Mittal Avatar answered Nov 14 '22 21:11

Sahil Mittal