2012-05-23 2 views
0

사용자가 내 응용 프로그램을 설치했는지 여부를 확인하려고합니다. 흐름은 다음과 같습니다.사용자가 내 앱을 설치했는지 여부를 확인하십시오. 하지만 Uncaught OAuthException (액세스 토큰)을 받으십시오.

1. Check whether has installed or authorize my app 
    2. If yes, then direct user to play my app directly 
     If no, then direct user to see welcoming page to read term of use and privacy. 

권한을 확인하기 위해 액세스 토큰을 갖고 있지 않은 것 같습니다. 아래 오류가 표시됩니다.

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

내 코드는 다음과 같습니다. 또한 $ access_token을 echo하여 액세스 토큰을 수신했는지 여부를 확인합니다. 예, 코드를 얻었습니다. 하지만 어쨌든 나는 여전히 오류가 발생합니다.

require_once('src/facebook.php'); 

$app_id = "APP_ID"; 
$app_secret = "APP_secret"; 

// Init facebook api. 
$facebook = new Facebook(array(
    'appId' => $app_id, 
    'secret' => $app_secret, 
    'cookie' => false, 
)); 

$access_token = $facebook->getAccessToken(); 
//echo $access_token; 

$permissions = $facebook->api("/me/permissions", $access_token); 
if(array_key_exists('publish_stream', $permissions['data'][0])) { 
    // Permission is granted! 
    echo "App has been installed"; 
    //then redirect to content page 
} else { 
    echo "App has not been installed"; 
    //then redirect user to welcoming page and let user read "term of use" and "privasy" 
} 

도와주세요.

답변

1

$access_tokenapi() 함수로 전달할 필요는 없습니다. 이 같은 API를 호출보십시오 :

$permissions = $facebook->api("/me/permissions");

를 문제가 해결되지 않으면, 당신은 최신 버전으로 페이스 북 SDK를 업그레이드해야 할 수 있습니다. 또한 사용자의 권한에 대해 API를 쿼리하기 전에 access_token이 실제로 반환되는지 확인하는 것이 좋습니다. 사용자가 아직 로그인하지 않고 앱을 승인 한 경우 코드가 실패합니다. 코드를 다음과 같이 변경하십시오.

$access_token = $facebook->getAccessToken(); 

if ($access_token) { 
    $permissions = $facebook->api("/me/permissions"); 
    if(array_key_exists('publish_stream', $permissions['data'][0])) { 
     // Permission is granted! 
     echo "App has been installed"; 
     //then redirect to content page 
    } else { 
     echo "App has not been installed"; 
     //then redirect user to welcoming page and let user read "term of use" and "privasy" 
    } 
} 
+0

답장을 보내 주셔서 감사합니다. 나는 최신 SDK를 사용하고 있다고 생각한다. 하지만 먼저 코드를 사용해 보도록하겠습니다. 계속 알려 드리겠습니다. API에 $ access_token을 전달하지 않으려 고했습니다. 저것은 didnt 일 그래서 나는 그것을 안으로 포함하는 것을 시도한다. – Nick

관련 문제