Cee*_*Bee 3 token facebook-php-sdk
我处于php的中级水平,并且是facebook开发的新手.我查看了facebook文档和Stack Overflow以前的评论.
我基本上想做的就是让用户使用他们的Facebook帐户登录并显示他们的名字.
我的php页面有一个图表,页面每2或5分钟自动刷新一次.
我验证并获取Facebook first_name以放在页面上.
$graph = $facebook->api('/me');
Run Code Online (Sandbox Code Playgroud)
echo $ graph ['first_name']获取用户的第一个名字..(我认为不需要访问令牌).
大约90分钟后.我一直收到错误:
fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user......
Run Code Online (Sandbox Code Playgroud)
并且我在$ facebook-> getUser()中没有值(0); 参数
我知道离线访问权限已被折旧,(我已在我的应用高级设置中启用此功能)
我正在尝试获取扩展访问令牌.在FB文档中.我知道了:
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
Run Code Online (Sandbox Code Playgroud)
我在链接中包含了我的信息(现有的有效访问令牌和所有)并收到了访问令牌:
access_token=AAADbZBPuUyWwBAFubPaK9E6CnNsPfNYBjQ9OZC63ZBN2Ml9TCu9BYz89frzUF2EnLttuZAcG2fWZAHbWozrvop9bQjQclxVYle7igvoZCYUAg2KNQLMgNP&expires=4050
Run Code Online (Sandbox Code Playgroud)
然而,这个令牌在约1小时左右到期.(.... expires = 4050)
我假设我使用服务器端身份验证因为我使用的是PHP?
我假设您需要在"应用高级设置"页面中启用"弃用offline_access".因为这对我有用:
//added code in base_facebook.php inside the facebook class
public function getExtendedAccessToken(){
try {
// need to circumvent json_decode by calling _oauthRequest
// directly, since response isn't JSON format.
$access_token_response =
$this->_oauthRequest(
$this->getUrl('graph', '/oauth/access_token'),
$params = array( 'client_id' => $this->getAppId(),
'client_secret' => $this->getAppSecret(),
'grant_type'=>'fb_exchange_token',
'fb_exchange_token'=>$this->getAccessToken(),
));
} catch (FacebookApiException $e) {
// most likely that user very recently revoked authorization.
// In any event, we don't have an access token, so say so.
return false;
}
if (empty($access_token_response)) {
return false;
}
$response_params = array();
parse_str($access_token_response, $response_params);
if (!isset($response_params['access_token'])) {
return false;
}
return $response_params['access_token'];
}
由于多种原因,令牌仍然无效,请参阅操作方法:处理过期的访问令牌.希望能帮助到你