autorizzazione app con PHP SDK
-
25-10-2019 - |
Domanda
Sto utilizzando il ultima Facebook PHP SDK e vuole i dati degli utenti semplicemente di accesso:
$facebook = new Facebook(array(
'appId' => 'xxx',
'secret' => 'yyy',
'cookie' => true
));
$user = $facebook->getUser();
if ($user) { // Checks if there is already a logged in user
try {
// Proceed knowing you have a logged in user who's already authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
else {
//Ask for bare minimum login
$login_url = $facebook->getLoginUrl();
header("Location: ".$login_url);
}
Il mio problema è che il $user
è FB effettuato l'accesso, ma $facebook->api('/me')
non solo non riesce, ma non si ottiene la finestra di autorizzazione app sia.
Che cosa sto facendo di sbagliato?
Soluzione
Alla fine ho trovato il mio errore così per la cronaca:
$facebook = new Facebook(array(
'appId' => 'xxxx',
'secret' => 'yyyyy',
'cookie' => true
));
$user = $facebook->getUser();
if ($user) { // Checks if there is already a logged in user
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
// Will throw the very first time as the token is not valid
error_log($e);
$user = null;
}
}
// $user is null : $user is either not logged in or the token is not valid
if(!$user) { //Ask for bare minimum login
$login_url = $facebook->getLoginUrl();
header("Location: ".$login_url);
}
Altri suggerimenti
Prova lo script demo FB all'indirizzo: https: / /github.com/facebook/facebook-php-sdk/blob/master/examples/example.php
vedere se funziona
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow