ShilleR
ShilleR

Reputation: 13

How to know if Facebook token is long-live or short-live

i'm building api for a project and i need to use facebook api, i have understood that the client get a short-live accessToken sent this token to the server, the server get a long-live accessToken and send back to the client, this is my code for this:

$token = Request::header('token');
$facebook = new Facebook(array(
      'appId'  => Config::get('facebook.app_id'),
      'secret' => Config::get('facebook.app_secret'),
));
$facebook->setAccessToken($token);
$user = $facebook->getUser();
if($user==0){
      return 'invalid token';
}
$facebook->setExtendedAccessToken();
$newToken = $facebook->getAccessToken();
return $newToken;

After that the client will save the newToken for the future requests, the problme is that the next time the client will send me a long-live token then i don't need to exchange the token with a long-live token because it's already a long-live token, how i can know if the token is long-live or short-live?

Upvotes: 1

Views: 1204

Answers (1)

fightbulc
fightbulc

Reputation: 140

Use the debug_token endpoint for facebook's graph: https://developers.facebook.com/docs/graph-api/reference/v2.2/debug_token

The token is a short lived token if data.issued_at is not set.

Upvotes: 1

Related Questions