Raptor
Raptor

Reputation: 54212

Facebook PHP SDK v4: AccessToken->getExpiresAt() does not return correct time

I use the following code to get expiration time of Access Token:

use Facebook\Entities\AccessToken;
$token_obj = new AccessToken($token);
$expires_at = $token_obj->getExpiresAt();
echo 'Expires At: ' .$expires_at . PHP_EOL;

$info = $token_obj->getInfo();
$info = $info->asArray();
echo 'Expires At (Info): ' . $info['expires_at'] . PHP_EOL;

which outputs:

Expires At: 0
Expires At (Info): 1438214400 // which is 2015-07-30 08:00:00

Why does the getExpiresAt() return incorrect result?

p.s.

Upvotes: 0

Views: 302

Answers (1)

Yassine Guedidi
Yassine Guedidi

Reputation: 1715

If you haven't saved the expiration timestamp value when getting the access token, then you must call getInfo() to get that value.

As you manually create an access token instance, I guess you have that value in a database. Then a solution would be to save the expires_at value in a new field when a user grant your app, it's returned with the new access token.

Upvotes: 1

Related Questions