本文介绍了使用setExtendedAccessToken()获取寿命长的访问令牌将返回寿命短的令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用来获取扩展的长期访问令牌

I try to get extended long-lived access token with

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

查看SDK之后,我发现setExtendedAccessToken()函数正在设置长期访问令牌

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');

使用

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

和getAccessToken()从中返回短期访问令牌

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

protected $accessToken

那么setExtendedAccessToken()的作用是什么,因为它不返回任何内容?

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

推荐答案

@Julian.非常感谢您的启发.我能够在不更改任何核心FB api文件的情况下完成这项工作.

@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.

发生的是,setExtendedAccessToken调用将值发送到setPersistentData,然后通过constructSessionVariableName将其发送到会话中.

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

因此,如果我们退出会话,然后将其设置到facebook对象中,就一切就绪.

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

这是我的代码:

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

这篇关于使用setExtendedAccessToken()获取寿命长的访问令牌将返回寿命短的令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 18:11