我遵循本教程 http://www.devils-heaven.com/facebook-access-tokens/
获取我的扩展访问令牌。我使用图形API方式放入我的appID / secret / limited令牌。然后我得到一个代码" Debug"它看看它是否确实有一个到期日 - 而且它没有。我把它插入我的代码,它工作正常,花花公子
今天早上回来,它不起作用。我需要一个新的访问令牌。为什么是这样?这种情况一直在发生。我究竟做错了什么?如果您需要查看我的代码,请告诉我。我通过JavaScript SDK进行FB登录并通过PHP发布
让我感到困惑的是,链接说他们可以被解雇只有60天(没有永久性),但是调试器说它永远不会过期(我认为它只能工作2个小时,因为它一直在我身上过期第二天醒来并做我的代码,看它是否有效)。为什么调试器告诉我它永远不会过期,即使我按照步骤获取扩展代码并且代码表明它永不过期?我很困惑。
eDIT-fyi我正在谈论USER访问令牌。页面访问令牌我从未根据调试器到期,每当我的代码停止工作时,我只需要更改用户访问令牌,它就会重新开始工作。
<?php
$accessToken = $_POST['accessToken'];
$pageId = $_GET['pageId'];
$fbAppId = '432036336937975';
$fbAppSecret = 'REMOVED FOR THE THREAD';
$appsecretProof = hash_hmac('sha256', $accessToken, $fbAppSecret);
//init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'facebook-php-3.2');
//get extended user access token
$url = 'https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token' .
'&client_id=' . $fbAppId .
'&client_secret=' . $fbAppSecret .
'&fb_exchange_token=' . $accessToken .
'&appsecret_proof=' . $appsecretProof;
curl_setopt($ch, CURLOPT_URL, $url);
$curlResult = curl_exec($ch);
$response_params = array();
parse_str($curlResult, $response_params);
$extendedUserToken = $response_params['access_token'];
$appsecretProof = hash_hmac('sha256', $extendedUserToken, $fbAppSecret);
//get extended page access token
$url = 'https://graph.facebook.com/' . $pageId .
'?fields=access_token' .
'&access_token=' . $extendedUserToken .
'&appsecret_proof=' . $appsecretProof;
curl_setopt($ch, CURLOPT_URL, $url);
$curlResult = curl_exec($ch);
curl_close($ch);
//$pageToken = json_decode($curlResult)->access_token;
//PAGE TOKEN NEVER EXPIRES
$pageToken = 'CAAGI70xkqZCcBAKzIhcnPRemwZCQ0zKdFtq5N0gTMmr54u9UECZA2WjoCUUrA4owy5FohSce0MCqPT7ouS8tqud5Ilhk1H1OxozucxTl4MxZBVZCM9ABjZB02xZC2G3ZBSaywwI8zoi7GiNiXf1E7C60xPZBTjP4VbqOOZCixPLdSlMCWQIUSdwvKYqCIpJ5qtWNWThGbDzZAtSW22vZBmiKoiTo';
//ACCESS TOKEN SHOULD NEVER EXPIRE
$data = http_build_query(array(
'access_token' => 'CAACEdEose0cBACrH119PGK52FvREQMLQh13vZAmghXKd4tJCKZCFzf9Yu1opzYNZCaQXZAhlCEqGOdgDTyjjDS7ZAYacuyWkyxHjNqpLZAZBboqAyNSNw7pzOnYnfD38XjYeu3qZCglERJBABoGdHQjZBDiYAoTHzaHijOzzPDndkTYCxHXzerqaCC59VOBsDwdcI6clb9idcEV1LhjFbmzXt',
'message' => 'hello world!'
));
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v2.1/1521533601413118/feed');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
curl_close($ch);
echo $pageToken;
?>