Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting long-lived access token with setExtendedAccessToken() returns short lived token

I try to get extended long-lived access token with

$facebook->setExtendedAccessToken();
$access_token = $facebook->getAccessToken();

After looking SDK I found that setExtendedAccessToken() function is setting long-lived access token in

protected static $kSupportedKeys =
array('state', 'code', 'access_token', 'user_id');

with

$this->setPersistentData(
  'access_token', $response_params['access_token']
);

and getAccessToken() is returning short-lived access token from

protected $accessToken

so what is the purpose of setExtendedAccessToken() since it does not return anything?

like image 721
user1633755 Avatar asked Aug 30 '12 12:08

user1633755


1 Answers

@Julian. Thank you so much for the inspiration here. I was able to make this work without changing any of the core FB api files.

What happens is, the setExtendedAccessToken call sends the value to setPersistentData which then sends it into session via constructSessionVariableName.

So if we get it out of session, and then set it into the facebook object, we're all set.

Here is my code:

// ask for the extended token and get it from session ...
$facebook->setExtendedAccessToken();
$access_token = $_SESSION["fb_".FB_APP_ID."_access_token"];
// now set it into the facebook object ....
$facebook->setAccessToken($access_token);
// now our fb object will use the new token as usual ...
$accessToken = $facebook->getAccessToken();
like image 148
writemcodeboy Avatar answered Oct 20 '22 15:10

writemcodeboy