2012-03-08 3 views
0

사용자를 인증하고 벽에 게시하면 로그 아웃하거나 계속 홈페이지로 돌아갈 수 있습니다 로그 아웃하고 다시 로그인하려고하면이 오류가 발생합니다.facebook php api는 로그인, 로그 아웃 및 로그백을 허용합니다. 정보를 쿼리하는 데 활성 액세스 토큰을 사용해야합니다.

Fatal error: Uncaught OAuthException: An active access token must be used to query 
information about the current user. thrown in ... 

로그인 상태를 유지하면 괜찮습니다.

jdk에서 FB.logout을 사용하여 스크립트를 로그 아웃 한 후 $ _SESSION [ 'active'] [$ access_token]을 null로 설정하면 페이스 북 로그인에서 페이지를 다시 연결하면 위의 오류. 그러나 스크립트가 사용자 데이터를 지우지 않습니다.

$ user = $ facebook-> getUser(); 내 문제의 일부인 이전 사용자 ID를 반환합니다.

여기

<?php 
//include the Facebook PHP SDK 
include_once 'facebook.php'; 

//instantiate the Facebook library with the APP ID and APP SECRET 
$facebook = new Facebook(array(
    'appId' => '162628977190080', 
    'secret' => '**MADE PRIVATE**', 
    'cookie' => true 
)); 

//Get the FB UID of the currently logged in user 
$user = $facebook->getUser(); 




//if the user has already allowed the application, you'll be able to get his/her FB UID 
if($user) { 

    //start the session if needed 
    if(session_id()) { 

    } else { 
     session_start(); 
    } 

    //do stuff when already logged in 

    //get the user's access token 
    $access_token = $facebook->getAccessToken(); 
    //check permissions list 
    $permissions_list = $facebook->api(
     '/me/permissions', 
     'GET', 
     array(
      'access_token' => $access_token 
     ) 
    ); 

    //check if the permissions we need have been allowed by the user 
    //if not then redirect them again to facebook's permissions page 
    $permissions_needed = array('publish_stream', 'email'); 
    foreach($permissions_needed as $perm) { 
     if(!isset($permissions_list['data'][0][$perm]) || $permissions_list['data'][0][$perm] != 1) { 
      $login_url_params = array(
       'scope' => 'publish_stream,email', 
       'fbconnect' => 1, 
       'display' => "page", 
       'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] 
      ); 
      $login_url = $facebook->getLoginUrl($login_url_params); 
      header("Location: {$login_url}"); 
      exit(); 
     } 
    } 

    //if the user has allowed all the permissions we need, 
    //get the information about the pages that he or she managers 
    $accounts = $facebook->api(
     '/me/accounts', 
     'GET', 
     array(
      'access_token' => $access_token 
     ) 
    ); 

    //save the information inside the session 
    $_SESSION['access_token'] = $access_token; 
    $_SESSION['accounts'] = $accounts['data']; 
    //save the first page as the default active page 
    $_SESSION['active'] = $accounts['data'][0]; 

    //redirect to manage.php 
    header('Location: ../facebook_result.php'); 
} else { 

    //if not, let's redirect to the ALLOW page so we can get access 
    //Create a login URL using the Facebook library's getLoginUrl() method 
    $login_url_params = array(
     'scope' => 'read_stream,email', 
     'fbconnect' => 1, 
     'display' => "page", 
     'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] 
    ); 
    $login_url = $facebook->getLoginUrl($login_url_params); 

    //redirect to the login URL on facebook 
    header("Location: {$login_url}"); 
    exit(); 
} 

?> 
+0

누구? 나는 이것에 관해 정말로 열매를 맺고있다. – jeremiah

답변

0

는 PHP의 많은 제거하고 자바 스크립트 SDK를 사용하여, 내가 원하는 일을하기 위해 다시 작성하는 세 개 미만의 시간이 걸렸다지고하여 해결 코드입니다.

관련 문제