2013-05-06 2 views
3

현재 LinkedIn Token을 가져 오는 데 문제가 있습니다.LinkedIn Get Token이 HTTP 1.1 400을 반환합니다 - 잘못된 요청 오류

나는 현재 developers documentation in order to get through authentication입니다. 내가하는 I가 인증 코드를 얻을, 인증 과정을 통과 한 후

나는 또한,

그러나 기본 코드로 this sample를 사용하고, 사용자에 대한 토큰을 얻기의 과정은 함께 실패 잘못된 요청 오류 (400)

다음

는 샘플 페이지에서 수정 된 코드입니다 (참고 : 주석 부분 우리 컬로 이동하기 전에 내가 만든 한 이전의 시도한다,있어)

public function getAccessToken() { 
     $params = array('grant_type' => 'authorization_code', 
      'client_id' => API_KEY, 
      'client_secret' => API_SECRET, 
      'code' => $_GET['code'], 
      'redirect_uri' => REDIRECT_URI.'/linkedin/auth', 
     ); 


     // Access Token request 
     $url = urldecode('https://www.linkedin.com/uas/oauth2/accessToken?'.http_build_query($params)); 
     //header("Content-length: ".strlen($url)); 
     // Tell streams to make a POST request 


     echo $url; 

     /*$context = stream_context_create(
      array('http' => 
      array('method' => 'POST', 
      ) 
      ) 
     );*/ 

     /*$context = stream_context_create(
         array('http' => 
          array('method' => 'POST', 
            'header' => 'Content-type: application/x-www-form-urlencoded', 
            'content' => http_build_query($params)) 
         ) 
        ); 

     // Retrieve access token information 
     $response = file_get_contents($url, FALSE, $context);*/ 


     $ch = curl_init(); 

     curl_setopt($ch,CURLOPT_URL, $url); 
     curl_setopt($ch,CURLOPT_POST,1); 
     $response = curl_exec($ch); 

     curl_close($ch); 

     $token = json_decode($response); 

     echo json_decode($response); 

     // Store access token and expiration time 
     $_SESSION['access_token'] = $token->access_token; // guard this! 
     $_SESSION['expires_in'] = $token->expires_in; // relative time (in seconds) 
     $_SESSION['expires_at'] = time() + $_SESSION['expires_in']; // absolute time 

     return true; 
} 
은 0

그런 깜빡하고 상기 echo $url; 부분은 수동 브라우저에 삽입하면 작동하라는 요구 위해서는

+0

당신이 시도 했나 '코드와 redirect_uri로 매개 변수 urlencode' :

이 줄을 제거? –

+0

@Yan 예 했어요. 그 결과도 마찬가지였다. 응답을받을 때 잘못된 요청입니다. 그러나 수동으로 브라우저에 URL을 삽입하는 것은 만료 시간 소인 및 액세스 토큰이있는 JSON 응답 인 것으로 예상대로 작동합니다. –

+2

'POST '대신'GET'으로 보내려고하셨습니까? –

답변

3

토큰이 유효한 사용자를 생성하는 URL을 출력하는 것이 아니라 GET 전송해야 POST.

curl_setopt($ch,CURLOPT_POST,1); 
관련 문제