<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Response code 400: grant_type parameter is missing in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Response-code-400-grant-type-parameter-is-missing/m-p/4969520#M345</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Plan: Premium&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country: USA&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device: Odroid H2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System: Linux 19.10&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I am working on a Java client. I have been able to access the whole API with no problem with the ironic exception of authorization. I would be quite happy if you could point me to any working Java example of getting the client_credentials token. The message I am currently getting and source code I am using are below:&lt;/P&gt;&lt;P&gt;Bad Request&lt;BR /&gt;400: Bad Request&lt;BR /&gt;{"error":"unsupported_grant_type","error_description":"grant_type parameter is missing"}&lt;BR /&gt;&amp;lt;&amp;lt;&amp;lt; Finished &amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;public static void main(final String[] args) {&lt;/P&gt;&lt;P&gt;getToken();&lt;/P&gt;&lt;P&gt;System.out.println("&amp;lt;&amp;lt;&amp;lt; Finished &amp;gt;&amp;gt;&amp;gt;");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;private static final String CHARSET = "UTF-8";&lt;BR /&gt;private static final String GRANT_TYPE = "client_credentials";&lt;/P&gt;&lt;P&gt;public static String getToken() {&lt;/P&gt;&lt;P&gt;String PAYLOAD;&lt;BR /&gt;try {&lt;BR /&gt;// PAYLOAD = String.format("client_id=%s&amp;amp;client_secret=%s&amp;amp;grant_type=%s",&lt;BR /&gt;// URLEncoder.encode(CLIENT_ID, CHARSET),&lt;BR /&gt;// URLEncoder.encode(CLIENT_SECRET, CHARSET),&lt;BR /&gt;// URLEncoder.encode(GRANT_TYPE, CHARSET));&lt;BR /&gt;PAYLOAD = "grant_type=" + URLEncoder.encode("client_credentials", "UTF-8");&lt;BR /&gt;} catch (final UnsupportedEncodingException x) {&lt;BR /&gt;PAYLOAD = "";&lt;BR /&gt;x.printStackTrace();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;String response = "";&lt;BR /&gt;try {&lt;BR /&gt;final URL url = new URL("&lt;A href="https://accounts.spotify.com/api/token" target="_blank" rel="noopener"&gt;https://accounts.spotify.com/api/token&lt;/A&gt;");&lt;BR /&gt;try {&lt;BR /&gt;final HttpURLConnection connection = (HttpURLConnection) url.openConnection();&lt;BR /&gt;connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");&lt;BR /&gt;connection.setRequestProperty("Accept", "application/json");&lt;BR /&gt;connection.setRequestProperty("grant_type", "client_credentials");&lt;BR /&gt;connection.setRequestProperty("Authorization", "Basic " + CLIENT_ID + ':' + CLIENT_SECRET);&lt;BR /&gt;connection.setRequestProperty("Content-Length", "" + PAYLOAD.length());&lt;BR /&gt;connection.setRequestMethod("POST");&lt;BR /&gt;connection.setDoInput(true);&lt;BR /&gt;connection.setDoOutput(true);&lt;/P&gt;&lt;P&gt;try (final DataOutputStream writer = new DataOutputStream(connection.getOutputStream())) {&lt;BR /&gt;writer.writeChars("PAYLOAD");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;if (connection.getResponseCode() == 200) {&lt;BR /&gt;try (final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {&lt;BR /&gt;while (reader.ready()) {&lt;BR /&gt;System.out.println(reader.readLine());&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;} else {&lt;BR /&gt;System.out.println(connection.getResponseMessage());&lt;BR /&gt;try (final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()))) {&lt;BR /&gt;while (reader.ready()) {&lt;BR /&gt;System.out.println(connection.getResponseCode() + ": " + connection.getResponseMessage());&lt;BR /&gt;System.out.println(reader.readLine());&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;} catch (final IOException x) {&lt;BR /&gt;x.printStackTrace();&lt;BR /&gt;}&lt;BR /&gt;} catch (final MalformedURLException x) {&lt;BR /&gt;x.printStackTrace();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;return response;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jun 2020 14:10:27 GMT</pubDate>
    <dc:creator>EdDowgiallo</dc:creator>
    <dc:date>2020-06-03T14:10:27Z</dc:date>
    <item>
      <title>Response code 400: grant_type parameter is missing</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Response-code-400-grant-type-parameter-is-missing/m-p/4969520#M345</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Plan: Premium&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country: USA&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device: Odroid H2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System: Linux 19.10&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I am working on a Java client. I have been able to access the whole API with no problem with the ironic exception of authorization. I would be quite happy if you could point me to any working Java example of getting the client_credentials token. The message I am currently getting and source code I am using are below:&lt;/P&gt;&lt;P&gt;Bad Request&lt;BR /&gt;400: Bad Request&lt;BR /&gt;{"error":"unsupported_grant_type","error_description":"grant_type parameter is missing"}&lt;BR /&gt;&amp;lt;&amp;lt;&amp;lt; Finished &amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;public static void main(final String[] args) {&lt;/P&gt;&lt;P&gt;getToken();&lt;/P&gt;&lt;P&gt;System.out.println("&amp;lt;&amp;lt;&amp;lt; Finished &amp;gt;&amp;gt;&amp;gt;");&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;private static final String CHARSET = "UTF-8";&lt;BR /&gt;private static final String GRANT_TYPE = "client_credentials";&lt;/P&gt;&lt;P&gt;public static String getToken() {&lt;/P&gt;&lt;P&gt;String PAYLOAD;&lt;BR /&gt;try {&lt;BR /&gt;// PAYLOAD = String.format("client_id=%s&amp;amp;client_secret=%s&amp;amp;grant_type=%s",&lt;BR /&gt;// URLEncoder.encode(CLIENT_ID, CHARSET),&lt;BR /&gt;// URLEncoder.encode(CLIENT_SECRET, CHARSET),&lt;BR /&gt;// URLEncoder.encode(GRANT_TYPE, CHARSET));&lt;BR /&gt;PAYLOAD = "grant_type=" + URLEncoder.encode("client_credentials", "UTF-8");&lt;BR /&gt;} catch (final UnsupportedEncodingException x) {&lt;BR /&gt;PAYLOAD = "";&lt;BR /&gt;x.printStackTrace();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;String response = "";&lt;BR /&gt;try {&lt;BR /&gt;final URL url = new URL("&lt;A href="https://accounts.spotify.com/api/token" target="_blank" rel="noopener"&gt;https://accounts.spotify.com/api/token&lt;/A&gt;");&lt;BR /&gt;try {&lt;BR /&gt;final HttpURLConnection connection = (HttpURLConnection) url.openConnection();&lt;BR /&gt;connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");&lt;BR /&gt;connection.setRequestProperty("Accept", "application/json");&lt;BR /&gt;connection.setRequestProperty("grant_type", "client_credentials");&lt;BR /&gt;connection.setRequestProperty("Authorization", "Basic " + CLIENT_ID + ':' + CLIENT_SECRET);&lt;BR /&gt;connection.setRequestProperty("Content-Length", "" + PAYLOAD.length());&lt;BR /&gt;connection.setRequestMethod("POST");&lt;BR /&gt;connection.setDoInput(true);&lt;BR /&gt;connection.setDoOutput(true);&lt;/P&gt;&lt;P&gt;try (final DataOutputStream writer = new DataOutputStream(connection.getOutputStream())) {&lt;BR /&gt;writer.writeChars("PAYLOAD");&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;if (connection.getResponseCode() == 200) {&lt;BR /&gt;try (final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {&lt;BR /&gt;while (reader.ready()) {&lt;BR /&gt;System.out.println(reader.readLine());&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;} else {&lt;BR /&gt;System.out.println(connection.getResponseMessage());&lt;BR /&gt;try (final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()))) {&lt;BR /&gt;while (reader.ready()) {&lt;BR /&gt;System.out.println(connection.getResponseCode() + ": " + connection.getResponseMessage());&lt;BR /&gt;System.out.println(reader.readLine());&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;} catch (final IOException x) {&lt;BR /&gt;x.printStackTrace();&lt;BR /&gt;}&lt;BR /&gt;} catch (final MalformedURLException x) {&lt;BR /&gt;x.printStackTrace();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;return response;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 14:10:27 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Response-code-400-grant-type-parameter-is-missing/m-p/4969520#M345</guid>
      <dc:creator>EdDowgiallo</dc:creator>
      <dc:date>2020-06-03T14:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Response code 400: grant_type parameter is missing</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Response-code-400-grant-type-parameter-is-missing/m-p/4972819#M407</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.spotify.com/t5/user/viewprofilepage/user-id/23733882"&gt;@EdDowgiallo&lt;/a&gt;, I might be able to help here!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hmm, I did some digging and I just wanted to check that the &lt;STRONG&gt;Authorization&lt;/STRONG&gt; is passed in the &lt;STRONG&gt;Header&lt;/STRONG&gt; of your request and that the &lt;STRONG&gt;grant_type&amp;nbsp;&lt;/STRONG&gt;is passed in the &lt;STRONG&gt;body of your POST request &lt;/STRONG&gt;(encoded as&amp;nbsp;&lt;SPAN&gt;application/x-www-form-urlencoded)&lt;/SPAN&gt;. Let me know if that helped here!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a good one,&lt;/P&gt;&lt;P&gt;Hubo&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 15:01:10 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Response-code-400-grant-type-parameter-is-missing/m-p/4972819#M407</guid>
      <dc:creator>Hubo</dc:creator>
      <dc:date>2020-06-08T15:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: Response code 400: grant_type parameter is missing</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Response-code-400-grant-type-parameter-is-missing/m-p/4972996#M425</link>
      <description>Sorry Hubo, but that is the way it is currently encoded and it does not work.&lt;BR /&gt;Do you have any example code for Java? If we get this working I would be happy to provide you with sample Java code for the entire API.&lt;BR /&gt;Ed</description>
      <pubDate>Mon, 08 Jun 2020 22:01:13 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Response-code-400-grant-type-parameter-is-missing/m-p/4972996#M425</guid>
      <dc:creator>EdDowgiallo</dc:creator>
      <dc:date>2020-06-08T22:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: Response code 400: grant_type parameter is missing</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Response-code-400-grant-type-parameter-is-missing/m-p/4980817#M562</link>
      <description>&lt;P&gt;Is there any other information I can provide to help resolve this issue?&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 15:00:50 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Response-code-400-grant-type-parameter-is-missing/m-p/4980817#M562</guid>
      <dc:creator>EdDowgiallo</dc:creator>
      <dc:date>2020-06-20T15:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Response code 400: grant_type parameter is missing</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Response-code-400-grant-type-parameter-is-missing/m-p/4991556#M675</link>
      <description>&lt;P&gt;Do you have a working example using Java? That would get me going.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ed&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 00:26:41 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Response-code-400-grant-type-parameter-is-missing/m-p/4991556#M675</guid>
      <dc:creator>EdDowgiallo</dc:creator>
      <dc:date>2020-07-07T00:26:41Z</dc:date>
    </item>
  </channel>
</rss>

