2012-09-08 4 views
4

"현재 사용자에 대한 정보를 쿼리하려면 활성 액세스 토큰을 사용해야합니다"오류가 나타납니다. 많은 기사와 아이디어가 있지만 매우 혼란스럽고 상황이 바뀌고있는 것처럼 보입니다. 많은 사람들이 오프라인 액세스를 사용한다고 말하지만 멀리 떨어져있는 것처럼 보입니다. 나는 this article을 찾았습니다.PHP sdk를 사용하여 새로운 access_token을 얻는 가장 좋은 방법

PHP SDK를 사용하는 사람이 있습니까?

아래 내용을 시도했지만 작동하지 않는 것 같습니다. $FBuser는 여전히 제로 :

$token_url = "https://graph.facebook.com/oauth/access_token?" . 
          "client_id=" . FB_APP_ID . 
          "&client_secret=" . FB_APP_SECRET . 
          "&grant_type=client_credentials"; 
list($name, $ACCESS_TOKEN) = explode("=", file_get_contents($token_url)); 
$facebook->setAccessToken(ACCESS_TOKEN); 
$FBuser = $facebook->getUser(); 

답변

0

이 (이 link에 따라 범위 매개 변수를 변경)보십시오 :

// Checks if the user granted the access (after the redirection bellow) 
$user = $facebook->getUser(); 
if(!$user) { 
    // If not: Retrieves the login url in order to redirect the user 
    $url = $facebook->getLoginUrl(array('scope' => 'user_about_me', 'grant_type' => 'client_credentials')); 
    // redirect here (after accepting the user will be redirect back to the same url. In other words this script, that will check again if the user is authenticated) 
} else { 
    // Now the user is authenticated 
    $user_data = $facebook->api('/me'); 
    $user_token = $facebook->getAccessToken(); 
    // Saves the access token 
} 
+0

을이 나쁜 방법입니다! offline_access가 사용되지 않습니다! '참고 : 2012 년 10 월 3 일에 offline_access 권한이 제거됩니다. ' https://developers.facebook.com/docs/authentication/ – Roni

+0

@Roni offline_access 때문에 다운 투표 했습니까? 그것은 단지 대답을 잘못하지 않는 매개 변수 일뿐입니다 .- ' –

+1

훌륭합니다! 당신은 페이스 북 가이드 라인을 따르지 않고 나쁜 모범을 보였습니다. 네, 최소한 투표를하는 것이 좋습니다. 왜냐하면 최소한이 코드 예제를 수정하는 데 도움이되지 않으면 "이 줄에있는 무엇인가"는 좋은 대답이 아니기 때문입니다. – Roni

관련 문제