2013-05-10 14 views
13

continuo a ricevere l'errore nel titolo, mentre si utilizza un codice semplice:Un token di accesso attivo deve essere usato per interrogare le informazioni sull'utente corrente

require_once('sdk/src/facebook.php'); 
require_once("AppInfo.php"); 
function idx(array $array, $key, $default = null) { 
    return array_key_exists($key, $array) ? $array[$key] : $default; 
} 
function he($str) { 
    return htmlentities($str, ENT_QUOTES, "UTF-8"); 
} 
$facebook = new Facebook(array(
    'appId' => AppInfo::appID(), 
    'secret' => AppInfo::appSecret(), 
    'sharedSession' => true, 
    'trustForwarded' => true, 
)); 

$arrayForJSON=array(); 
$user = $facebook->getUser(); 
$friends = idx($facebook->api('/me/friends'), 'data', array()); 
if ($friends) { 
    $arrayForJSON['friends']=$friends; 
} 
print_r($friends); 

io davvero non so come risolverlo, Ho cercato e provato molte risposte su StackOverflow

+1

Si prega di seguire le istruzioni su questo link: - http://stackoverflow.com/questions/11776234/an -Active-access-token-deve-essere-usato-per-query-informazioni-su-the-current-user/18.252.089 18.252.089 # –

risposta

2

È necessario impostare il token di accesso per poter ottenere dati o agire per conto dell'utente. Stai attraversando un flusso di accesso per consentire l'autorizzazione alla tua applicazione Facebook?

Prova l'esempio a https://developers.facebook.com/docs/reference/php/facebook-api/

Esso fornisce il flusso di accesso molto di base che garantirà l'accesso ai dati che state cercando.

2

è necessario verificare se già il login, se non reindirizzare l'utente per accedere collegamento

require '../src/facebook.php'; 

// Create our Application instance (replace this with your appId and secret). 
$facebook = new Facebook(array(
    'appId' => '191149314281714', 
    'secret' => '73b67bf1c825fa47efae70a46c18906b', 
)); 

// Get User ID 
$user = $facebook->getUser(); 

// We may or may not have this data based on whether the user is logged in. 
// 
// If we have a $user id here, it means we know the user is logged into 
// Facebook, but we don't know if the access token is valid. An access 
// token is invalid if the user logged out of Facebook. 

if ($user) { 
    try { 
    // Proceed knowing you have a logged in user who's authenticated. 
    // $user_profile = $facebook->api('/me'); 
    $friends = idx($facebook->api('/me/friends'), 'data', array()); 

    } catch (FacebookApiException $e) { 
    error_log($e); 
    $user = null; 
    } 
} 

// Login or logout url will be needed depending on current user state. 
if ($user) { 
    $logoutUrl = $facebook->getLogoutUrl(); 
} else { 
    $loginUrl = $facebook->getLoginUrl(array('scope'=>'offline_access')); 
} 
Problemi correlati