title: Spotify API - error retrieving access token during authorization process
body: <p>I'm building my first Spotify application and right now I'm tackling the authorization process. </p>
  
  <p>So far I have been successful in retrieving my State and Code from <a href="https://accounts.spotify.com/authorize" rel="nofollow">https://accounts.spotify.com/authorize</a> </p>
  
  <p>and now I'm sending a POST request via PHP CURL request to acquire my access token.</p>
  
  <p><a href="http://i.stack.imgur.com/1arEi.png" rel="nofollow">Spotify's instructions for this step</a></p>
  
  <p>I keep getting the following JSON error response indicating that my grant_type is not valid and it offers me three valid options:</p>
  
  <p>{"error":"unsupported_grant_type","error_description":"grant_type must be client_credentials, authorization_code or refresh_token"}bool(true)</p>
  
  <p>If you look at my code below, I believe I have set the correct grant_type of "authorization_code" but I'm getting the error. I have highlighted with '******' the code snippet of what I believe to be the correct line of code.</p>
  
  <p>Can anyone see what I'm doing incorrectly? Here's the code I'm using to send the request:</p>
  
  <pre><code>    //  Get access tokens
          $ch = curl_init();              
          // Specify the HTTP headers to send.
                  //Authorization: Basic &lt;base64 encoded client_id:client_secret&gt;
                  $ClientIDSpotify = "[my spotify app id]";
                  $ClientSecretSpotify = "[my secret code]";
                  $authorization = base64_encode ( "{$ClientIDSpotify}:{$ClientSecretSpotify}" );
                  $http_headers = array( 
                              "Authorization: Basic {$authorization}"
                          );
                  curl_setopt( $ch, CURLOPT_HTTPHEADER, $http_headers );
          curl_setopt( $ch, CURLOPT_POST, true);
  
          $spotify_url = "https://accounts.spotify.com/api/token";
          curl_setopt( $ch, CURLOPT_URL, $spotify_url );
  
  
  
          // *************************************************
          // HERE'S WHERE I CORRECTLY SPECIFY THE GRANT TYPE
          // *************************************************
          $data['grant_type'] = "authorization_code";
          $data['code'] = $authorizationCode;
          $callbackURL = "[my callback URL]";     
          $data['redirect_uri'] = $callbackURL;    
  
          curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
          curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
          $response_json = curl_exec( $ch );
          curl_close( $ch );
      }
  </code></pre>