<?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 HTML page instead of response in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/HTML-page-instead-of-response/m-p/5644636#M10949</link>
    <description>&lt;P&gt;Hello, I would like to write an application in Kotlin that uses the Spotify API. To start with I would like to just understand what is going on and wrote the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;val &lt;/SPAN&gt;&lt;SPAN&gt;client &lt;/SPAN&gt;= &lt;SPAN&gt;HttpClient&lt;/SPAN&gt;(CIO)&lt;BR /&gt;&lt;SPAN&gt;suspend fun &lt;/SPAN&gt;&lt;SPAN&gt;main&lt;/SPAN&gt;(args: Array&amp;lt;String&amp;gt;) {&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;val &lt;/SPAN&gt;otvet:String=&lt;SPAN&gt;client&lt;/SPAN&gt;.post(&lt;SPAN&gt;"&lt;A href="https://accounts.spotify.com/api/token" target="_blank" rel="noopener"&gt;https://accounts.spotify.com/api/token&lt;/A&gt;"&lt;/SPAN&gt;)&lt;SPAN&gt;{&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;headers&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;"Content-Type: application/x-www-form-urlencoded"&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;setBody&lt;/SPAN&gt;(&lt;SPAN&gt;"grant_type=client_credentials&amp;amp;client_id=000&amp;amp;client_secret=000"&lt;/SPAN&gt;)&lt;BR /&gt;    &lt;SPAN&gt;}&lt;/SPAN&gt;.body()&lt;BR /&gt;    &lt;SPAN&gt;println&lt;/SPAN&gt;(otvet)&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I removed the key and secret key)&lt;BR /&gt;But instead of what was described here: &lt;A href="https://developer.spotify.com/documentation/web-api/tutorials/getting-started" target="_blank" rel="noopener"&gt;https://developer.spotify.com/documentation/web-api/tutorials/getting-started&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I got an HTML page that opens if I open &lt;A href="https://accounts.spotify.com/api/token" target="_blank" rel="noopener"&gt;https://accounts.spotify.com/api/token&lt;/A&gt; directly in the browser. How to fix it?&lt;/P&gt;</description>
    <pubDate>Sun, 01 Oct 2023 11:34:18 GMT</pubDate>
    <dc:creator>A_CH_V</dc:creator>
    <dc:date>2023-10-01T11:34:18Z</dc:date>
    <item>
      <title>HTML page instead of response</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/HTML-page-instead-of-response/m-p/5644636#M10949</link>
      <description>&lt;P&gt;Hello, I would like to write an application in Kotlin that uses the Spotify API. To start with I would like to just understand what is going on and wrote the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;val &lt;/SPAN&gt;&lt;SPAN&gt;client &lt;/SPAN&gt;= &lt;SPAN&gt;HttpClient&lt;/SPAN&gt;(CIO)&lt;BR /&gt;&lt;SPAN&gt;suspend fun &lt;/SPAN&gt;&lt;SPAN&gt;main&lt;/SPAN&gt;(args: Array&amp;lt;String&amp;gt;) {&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;val &lt;/SPAN&gt;otvet:String=&lt;SPAN&gt;client&lt;/SPAN&gt;.post(&lt;SPAN&gt;"&lt;A href="https://accounts.spotify.com/api/token" target="_blank" rel="noopener"&gt;https://accounts.spotify.com/api/token&lt;/A&gt;"&lt;/SPAN&gt;)&lt;SPAN&gt;{&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;headers&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;"Content-Type: application/x-www-form-urlencoded"&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;setBody&lt;/SPAN&gt;(&lt;SPAN&gt;"grant_type=client_credentials&amp;amp;client_id=000&amp;amp;client_secret=000"&lt;/SPAN&gt;)&lt;BR /&gt;    &lt;SPAN&gt;}&lt;/SPAN&gt;.body()&lt;BR /&gt;    &lt;SPAN&gt;println&lt;/SPAN&gt;(otvet)&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I removed the key and secret key)&lt;BR /&gt;But instead of what was described here: &lt;A href="https://developer.spotify.com/documentation/web-api/tutorials/getting-started" target="_blank" rel="noopener"&gt;https://developer.spotify.com/documentation/web-api/tutorials/getting-started&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I got an HTML page that opens if I open &lt;A href="https://accounts.spotify.com/api/token" target="_blank" rel="noopener"&gt;https://accounts.spotify.com/api/token&lt;/A&gt; directly in the browser. How to fix it?&lt;/P&gt;</description>
      <pubDate>Sun, 01 Oct 2023 11:34:18 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/HTML-page-instead-of-response/m-p/5644636#M10949</guid>
      <dc:creator>A_CH_V</dc:creator>
      <dc:date>2023-10-01T11:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: HTML page instead of response</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/HTML-page-instead-of-response/m-p/5644654#M10951</link>
      <description>&lt;P&gt;Howling hello to you A_CH_V!&lt;BR /&gt;It seems like you’re facing an issue where the Spotify API is returning an HTML page instead of the expected response. This could be due to incorrect request parameters or headers. Here are a few things to check:&lt;/P&gt;&lt;P&gt;1. URL Encoding: Make sure the parameters in the setBody function are URL encoded properly.&lt;BR /&gt;2. Header Formatting: Ensure that the header is in the correct format. In this case, the “Content-Type” header should be separated by a colon.&lt;BR /&gt;3. Client Credentials: Double-check that the client ID and client secret you’re using are correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here’s a corrected version of your code with these considerations:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import io.ktor.client.HttpClient
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.request.headers
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.content.TextContent

suspend fun main(args: Array&amp;lt;String&amp;gt;) {
    val clientId = "YOUR_CLIENT_ID"
    val clientSecret = "YOUR_CLIENT_SECRET"

    val client = HttpClient {
        install(JsonFeature)
    }

    val response = client.post&amp;lt;String&amp;gt;("https://accounts.spotify.com/api/token") {
        headers {
            append("Content-Type", ContentType.Application.FormUrlEncoded.toString())
        }
        body = TextContent(
            "grant_type=client_credentials&amp;amp;client_id=$clientId&amp;amp;client_secret=$clientSecret",
            ContentType.Application.FormUrlEncoded
        )
    }

    println(response)
}&lt;/LI-CODE&gt;&lt;P&gt;Replace "YOUR_CLIENT_ID" and "YOUR_CLIENT_SECRET" with your actual Spotify API client ID and secret. Ensure that the content type and request body are formatted correctly. If the issue persists, double-check your Spotify API credentials and request format.&lt;/P&gt;&lt;P&gt;I’ll be barking up the wrong tree without any updates,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Prague the Dog&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Oct 2023 12:43:07 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/HTML-page-instead-of-response/m-p/5644654#M10951</guid>
      <dc:creator>Prague</dc:creator>
      <dc:date>2023-10-01T12:43:07Z</dc:date>
    </item>
  </channel>
</rss>

