Sulla base facebook instructions (Scenario 4) sto usando il seguente URLaccesso facebook di token scaduto
https://graph.facebook.com/oauth/access_token?client_id=APP_ID&client_secret=CLIENT_SECRET& grant_type=fb_exchange_token&fb_exchange_token=OLD_ACCESS_TOKEN
per ottenere il nuovo token di accesso, ma ottengo il seguente:
{ "errore": il messaggio { " ": "Errore accesso convalidando token: La sessione è scaduta al momento unix 1365257820. Il tempo unix attuale è 1365759029.", "type": "OAuthException", "codice": 190, "error_subcode": 463}}
non funziona. Qualsiasi aiuto apprezzato.
EDIT: Capito! Funziona in questo modo
se token di accesso scade eseguire lo script php sotto prima sul browser dopo di memorizzare sul vostro server
<?php
$app_id = "your app id";
$app_secret = "your app secret";
$my_url = "http://apps.facebook.com/your_app_name";
// known valid access token stored in a database
$access_token = "your old access token";
$code = $_REQUEST["code"];
// If we get a code, it means that we have re-authed the user
//and can get a valid access_token.
if (isset($code)) {
$token_url="https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code . "&display=popup";
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
}
// Attempt to query the graph:
$graph_url = "https://graph.facebook.com/me?"
. "access_token=" . $access_token;
$response = curl_get_file_contents($graph_url);
$decoded_response = json_decode($response);
//Check for errors
if ($decoded_response->error) {
// check to see if this is an oAuth error:
if ($decoded_response->error->type== "OAuthException") {
// Retrieving a valid access token.
$dialog_url= "https://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url
. "'</script>");
}
else {
echo "other error has happened";
}
}
else {
// success
echo("success" . $decoded_response->name);
echo($access_token);
}
// note this wrapper function exists in order to circumvent PHP’s
//strict obeying of HTTP error codes. In this case, Facebook
//returns error code 400 which PHP obeys and wipes out
//the response.
function curl_get_file_contents($URL) {
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
$err = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
?>
lo script di cui sopra vi darà un URL come quella qui sotto sul browser
https://graph.facebook.com/oauth/access_token?code= ...
quindi ottenere la stringa (dovrebbe essere qualcosa di simile: AQCn41Svv5DbWrnFY0Wf ..... YbNm_yz2rE # _) dopo il codice = e incollarlo sul codice = URL sotto ed eseguire il seguente URL nel browser
si otterrà il seguente rispondere che è un nuovo token di accesso per 60 giorni
access_token=<Extended_Access_Token>&expires=5180130
copiare e incollare la stringa dopo the access_token = allo script sul tuo server che pubblica i nuovi post sulla tua pagina
Ciò significa che il vostro vecchio token di accesso è già scaduto. Potresti riprovare la stessa cosa con un nuovo token di accesso di breve durata –
grazie che l'ho fatto con un nuovo token di accesso di breve durata – stefanosn
Hai appena scritto il token di accesso al mondo, per favore fai attenzione. Chiunque può abusarne. –