1
我需要更新一個長壽命的訪問令牌。我讀 Renew long lived access token server side話題,寫了代碼如下:得到一個新的短命用戶access_token
<?php
$code = $_REQUEST["code"];
if(empty($code)) {
$dialog_url = "https://www.facebook.com/dialog/oauth?"
. "client_id=$app_id"
. "&redirect_uri=$my_url"
. "&scope=..."
;
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
else
{
$response = file_get_contents("https://graph.facebook.com/oauth/access_token?"
. "client_id=$app_id"
. "&redirect_uri=$my_url"
. "&client_secret=$app_secret"
. "&code=$code"
);
$params = null;
parse_str($response, $params);
$access_token=$params['access_token'];
$response = file_get_contents("https://graph.facebook.com/oauth/access_token?"
. "client_id=$app_id"
. "&client_secret=$app_secret"
. "&redirect_uri=$my_url"
. "&grant_type=fb_exchange_token"
. "&fb_exchange_token=$access_token"
);
}
?>
第一次調用它獲得60天的訪問令牌的所有權利。我預計在下一次調用時它會獲得另一個(可能具有相同名稱)的60天令牌,並且我會在調試器https://developers.facebook.com/tools/debug中看到發佈時間和到期時間會發生變化,但時間不會改變。我的方案有什麼問題?