title: LinkedIn API OAuth2 - Unable to retrieve access token
body: <p>I'm trying to get an access token on the LinkedIn API but I get the following error :</p>
  
  <pre><code>{"error":"invalid_request","error_description":"Unable to retrieve access token: appid or redirect uri does not match authorization code or authorization code expired"}
  </code></pre>
  
  <p>PHP code :</p>
  
  <p>Get the authorization code (work): </p>
  
  <pre><code>$linkedIn = array(
          'clientId' =&gt; 'My id',
          'redirectUri' =&gt; WEBSITE.'User/liCallback/',
          'state' =&gt; 'rz5t4er6t7re68t7e6rt6ze9',
          'scope' =&gt; 'r_basicprofile'
      );
      $liLoginUrl = 'https://www.linkedin.com/oauth/v2/authorization?response_type=code&amp;client_id='.$linkedIn['clientId'].'&amp;redirect_uri='.$linkedIn['redirectUri'].'?state='.$linkedIn['state'].'&amp;scope='.$linkedIn['scope'];
  </code></pre>
  
  <p>Get the access toekn (doesn't work) : </p>
  
  <pre><code> public function liCallback(){
    $linkedin =   array(
        'grant_type' =&gt; 'authorization_code',
        'code' =&gt; $this-&gt;get('code'),
        'redirectUri' =&gt; WEBSITE.'User/liCallback/',
        'client_id' =&gt; 'My id',
        'client_secret' =&gt; 'My client secret'
    );
  
  
  
    $curl_handle=curl_init();
    curl_setopt($curl_handle, CURLOPT_URL,'https://www.linkedin.com/oauth/v2/accessToken');
    curl_setopt($curl_handle, CURLOPT_POST, 1);
    echo curl_setopt($curl_handle, CURLOPT_POSTFIELDS, 'grant_type='.$linkedin['grant_type'].'&amp;code='.$this-&gt;get('code').'&amp;redirect_uri='.urlencode($linkedin['redirectUri']).'&amp;client_id='.$linkedin['client_id'].'&amp;client_secret='.$linkedin['client_secret']);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_handle, CURLOPT_USERAGENT, 'x-www-form-urlencoded');
    $query = curl_exec($curl_handle);
    var_dump($query);
    curl_close($curl_handle);
  
  }
  </code></pre>
  
  <p>I try to use encodeurl() but I got the same error.
  I try with file_get_content() but I got an 400 error.</p>
  
  <p>Thanks for help !</p>