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

前端 未结 2 1112
-上瘾入骨i
-上瘾入骨i 2020-12-09 06:16

I try to get extended long-lived access token with

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

2条回答
  •  眼角桃花
    2020-12-09 07:03

    @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();
    

提交回复
热议问题