所以我承认自己是facebook Graph api的新手,但我想做的事情感觉应该是可行的。
我想要做的只是显示我在网站上拥有的Facebook页面上的帖子。
现在我应该说我已经用api和php sdk实现了这一点,但它的所有访问令牌都让我感到困惑,我只想要一个永久访问令牌,这样我就不用续订了无论如何。
非常感谢任何帮助
答案 0 :(得分:0)
以防万一有人登陆这个问题,并且正在寻找关于这个问题的方向
$client = array(
"id" => {APP_ID},
"secret" => {APP_SECRET},
"token" => {ACCESS_TOKEN}, // Generated from the graph api explorer, with the 'manage_posts' extended permission ticked
"page" => {PAGE_ID}
);
FacebookSession::setDefaultApplication($client['id'], $client['secret']);
$session = new FacebookSession($client['token']);
try
{
$response = (new FacebookRequest($session, 'GET', '/oauth/access_token?grant_type=fb_exchange_token&client_id='.$client['id'].'&client_secret='.$client['secret'].'&fb_exchange_token='.$client['token']))->execute();
$results = $response->getGraphObject();
$data = $results->asArray();
$token = $data['access_token'];
$response = (new FacebookRequest($session, 'GET', '/'.$client['page'].'?fields=access_token'))->execute();
$results = $response->getGraphObject();
$data = $results->asArray();
echo "Access Token: ".$data['access_token']; // this is your never expiring access token
}
catch (FacebookRequestException $e) {
print_r($e);
}
catch (\Exception $e) {
print_r($e);
}
显然我不建议在任何形式的生产环境中执行此操作,但如果您在本地环境中并且只需要访问令牌,请随意使用它来查找访问令牌。