APP APP APP DI BAD BAD INTERMITTENTE
-
27-10-2019 - |
Domanda
Sto creando utenti di test su Facebook per la mia applicazione. A volte funziona. Quando non lo fa, l'errore si verifica in questa chiamata:
function getTestAccounts($fb, $a) {
$s = urlencode($a);
**$accounts = $fb->api("/{$fb->getAppId()}/accounts/test-users?access_token=$s");**
if( isset($accounts['data']) )
return $accounts;
else
return null;
}
L'errore è:
OauthException non integrato: (#15) Questo metodo deve essere chiamato con un'app Access_Token.
In precedenza ho ottenuto il token con questa funzione:
function getAppAccessToken($fb) {
$access_token_url = "https://graph.facebook.com/oauth/access_token";
$parameters = "grant_type=client_credentials&client_id=" . $fb->getAppId() . "&client_secret=" . $fb->getApiSecret() . "&junk=1";
return file_get_contents($access_token_url . "?" . $parameters);
}
Quando produco il token offensivo, assomiglia a questo e non cambia (dovrebbe?)
Access_Token = 229234510434203 | tk2udogcpthcbedehripksg8wk
Ho provato a cancellare i biscotti. Sembrava funzionare, ma avrebbe potuto coincidere con qualcos'altro perché non lo fa ora.
Presumo che il token di accesso sia tornato dai cambiamenti di FB, ma torna sempre lo stesso.
Soluzione 2
Ho fatto un errore di Greenhorn. Quello che non ho notato era che questo problema si stava verificando solo dopo aver aperto un'altra scheda del browser e registrato su Facebook come me stesso o un utente di prova. La nuova sessione di Facebook stava interferendo con l'API.
Immagino che l'API utilizzi il token di accesso dell'utente registrato invece di ciò che è passato nella richiesta. Un po 'ovvio una volta capito!
Spero che questo aiuti la prossima persona :-)
Altri suggerimenti
Segno
Per un token di accesso utente utilizzo il seguente, in cui il numero è il mio ID app. "Utilizzato con PHP-SDK"
$access_token = $_SESSION['fb_135669679827333_access_token'];
Per un token di accesso all'applicazione uso Curl
$app_access_token = GetCH();
function GetCH(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if(substr($url,0,8)=='https://'){
// The following ensures SSL always works. A little detail:
// SSL does two things at once:
// 1. it encrypts communication
// 2. it ensures the target party is who it claims to be.
// In short, if the following code is allowed, CURL won't check if the
// certificate is known and valid, however, it still encrypts communication.
curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_ANY);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
}
$sendCH = curl_exec($ch);
curl_close($ch);
return $sendCH;
};
Fammi sapere se questo aiuta.