简体   繁体   English

Facebook用户访问令牌PHP

[英]Facebook User Access Token PHP

As stated on the Facebook documentation, access tokens are portables, that means that an access token could be obtained on the front-end side of the application and passed to the back-end side to handle Graph API requests. 如Facebook文档所述, 访问令牌是可移植的,这意味着访问令牌可以在应用程序的前端获得,并传递到后端以处理Graph API请求。

The problem is: how to properly instantiate and setup the Access Token in the back-end side? 问题是:如何在后端正确地实例化和设置访问令牌?

I'm currently doing the following code: 我目前正在执行以下代码:

use Facebook\Authentication\AccessToken;
$accessToken = new AccessToken('{access-token goes here}');
print_r($accessToken); // inspecting the token

When print_r is called, some of the token information are missing, such as the expiresAt attribute. 调用print_r时 ,缺少某些令牌信息,例如expiresAt属性。 This attribute, for instance, is present when the access token is generated by the FacebookRedirectLoginHelper::getAccessToken on the callback process. 例如,当回调令牌上的FacebookRedirectLoginHelper :: getAccessToken生成访问令牌时,就会出现此属性。

Does the lack of this attribute interferes on the flow of things? 缺少此属性是否会干扰事物的流动? If so, then how to properly instantiate a portable Access Token in the back-end ? 如果是这样,那么如何在后端正确地实例化可移植的访问令牌

Have a look at 看一下

Sample code: 样例代码:

var_dump($accessToken->getValue());

// The OAuth 2.0 client handler helps us manage access tokens
$oAuth2Client = $fb->getOAuth2Client();

// Get the access token metadata from /debug_token
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
echo '<h3>Metadata</h3>';
var_dump($tokenMetadata);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM