Domanda

Sto cercando di creare un app Instagram utilizzando la libreria PHP che è qui (non è molto lungo di file, non preoccupatevi):

http://pastie.org/3391787

Sto cercando di autorizzare l'utente utilizzando OAuth, che funziona perfettamente, e il (utente corrente) autorizzato può vedere le sue informazioni (come immagine, il nome ecc ...), ma quando ho aggiorna la pagina tutto va e io sono rimasto con i dati in bianco, ecco il codice -

// Instantiate the API handler object
$instagram = new Instagram($config);
$accessToken = $instagram->getAccessToken();
$_SESSION['InstagramAccessToken'] = $accessToken;

$instagram->setAccessToken($_SESSION['InstagramAccessToken']);
$userinfo = $instagram->getUser($_SESSION['InstagramAccessToken']);

// After getting the response, let's iterate the payload
$ures = json_decode($userinfo, true);

questo codice funziona bene al primo turno tempo, ma quando si aggiorna la pagina, le informazioni non viene recuperata, e che poteva solo una cosa da poco, che la sessione o il cookie non è impostato correttamente e questo è il motivo per cui il metodo getUser non è il recupero delle informazioni,

$userinfo = $instagram->getUser($_SESSION['InstagramAccessToken']);

si può fare un po 'di luce in questo problema, ho cercato per 4 ore !!

È stato utile?

Soluzione

In ogni vostra richiesta si sovrascrive i dati della sessione in corso con nulla da questa linea:

$_SESSION['InstagramAccessToken'] = $accessToken;

Molto probabilmente questo è come dovrebbe essere simile:

$instagram = new Instagram($config);

if (!empty($_SESSION['InstagramAccessToken'])) {
    $accessToken = $instagram->getAccessToken();
    $_SESSION['InstagramAccessToken'] = $accessToken;
} else {
    $instagram->setAccessToken($_SESSION['InstagramAccessToken']);
}

$userinfo = $instagram->getUser($_SESSION['InstagramAccessToken']);

// After getting the response, let's iterate the payload
$ures = json_decode($userinfo, true);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top