Php 使用LinkedIn访问令牌时出错

Php 使用LinkedIn访问令牌时出错,php,http,post,curl,linkedin,Php,Http,Post,Curl,Linkedin,经过多次测试后,我无法检索访问令牌。每次出现此错误时,它都会告诉我: "error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : authorization code not found","error":"invalid_request" 我完全心烦意乱。有

经过多次测试后,我无法检索访问令牌。每次出现此错误时,它都会告诉我:

"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : authorization code not found","error":"invalid_request"
我完全心烦意乱。有几天我无法解决我的问题

以下是我的申请代码:

Route::get('login/linkedin', function()
{
$lk_credentials = Config::get('linkedin.public0');
$provider = new LinkedIn($lk_credentials);
if(!Input::has('code')){
    $provider->authorize();
}else{
    $code = Input::get('code');
    if(strlen($code) == 0) return Redirect::to('/')->with('message', 'There was an error communicating with LinkedIn');
    try{
        $params = array(
            'response_type' => 'code',
            'client_id' => '*************',
            'redirect_uri' => urlencode(url('login/linkedin')),
            'state' => $_GET['state'],
        );
        $postdata = http_build_query($params);
        $url = '/uas/oauth2/authorization?'.$postdata;
        $context = stream_context_create(array('https' => array('method' => 'GET')));
        $t = $provider->getAccessToken('authorization_code', array('code' => $_GET['code']));
        Session::put('oauth2_access_token', $t->accessToken);session(['oauth2_access_token' => $t->accessToken]);
        try{
            if(count($_POST) > 0){
                print_r($_POST);
                exit('post');
            }
            $params = array(
                'grant_type' => 'authorization_code',
                'code' => Session::get('oauth2_access_token'), //$_GET['code'],
                'redirect_uri' => urlencode(url('login/linkedin')),
                'client_id' => '123456789',
                'client_secret' => '123456789',
            );
            $postdata = http_build_query($params);
            $c = curl_init();
            curl_setopt($c, CURLOPT_URL, 'https://www.linkedin.com/uas/oauth2/accessToken');
            curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($c, CURLOPT_POST,true);
            curl_setopt($c, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($c, CURLOPT_POSTFIELDS,$postdata);
            curl_setopt($c, CURLOPT_HEADER, false);
            curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded',));
            $output = curl_exec($c);
            if($output === false){
                trigger_error('Erreur curl : '.curl_error($c),E_USER_WARNING);
                exit('Erreur');
            }else{
                var_dump($output);
                //exit('Affiche');
            }
            curl_close($c);
        }catch(Exception $e){
            return 'Unable to get Request Token';
        }
    }catch(Exception $e){
        return 'Unable to get user authorization_code';
    }
    try{
        $resource = '/v1/people/~:(id,emailAddress,firstName,lastName,pictureUrl,dateOfBirth,location)';
        $params = array(
            'oauth2_access_token' => Session::get('oauth2_access_token'), 
            'format' => 'json',
        );
        $url = 'https://api.linkedin.com' . $resource . '?' . http_build_query($params);
        $context = stream_context_create(array('http' => array('method' => 'GET')));
        $response = file_get_contents($url, false, $context);
        $data = json_decode($response);
        Session::put('data', $data);session(['data' => $data]);
        return redirect('/')->with('data',$data);
    }catch(Exception $e){
        return 'Unable to get user details';
    }
}
}))

有人能帮我吗

供参考;我使用Laravel5,身份验证使用OAuth2


提前感谢您,David。

我看不到您的代码中有任何地方要求使用授权码来交换访问令牌。我建议您阅读LinkedIn的OAuth 2.0文档,以确保您遵循了所有正确的步骤:感谢您的帮助!但是授权码没有在第一个“try{}”中检索它?您的重定向uri值是否是您在LinkedIn应用程序配置中配置的有效完全限定URL?是的,我的重定向uri在LinkedIn应用程序配置中配置良好。我不明白我的问题。。。