Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法通过在Kotlin中创建截击Post请求来获取Spotify访问令牌_Android_Http_Kotlin_Post_Android Volley - Fatal编程技术网

Android 无法通过在Kotlin中创建截击Post请求来获取Spotify访问令牌

Android 无法通过在Kotlin中创建截击Post请求来获取Spotify访问令牌,android,http,kotlin,post,android-volley,Android,Http,Kotlin,Post,Android Volley,我试图通过在Kotlin中创建POST请求来获取Spotify访问令牌,但当我尝试执行该请求时,得到400错误响应代码: // Obtain an access token to get authorized for the Spotify Web API val APIRequestURL = "https://accounts.spotify.com/api/token" val queue = Volley.newReq

我试图通过在Kotlin中创建POST请求来获取Spotify访问令牌,但当我尝试执行该请求时,得到400错误响应代码:

// Obtain an access token to get authorized for the Spotify Web API
            val APIRequestURL = "https://accounts.spotify.com/api/token"

            val queue = Volley.newRequestQueue(requireActivity())

            val postRequest = object : StringRequest(
                Method.POST, APIRequestURL,
                Response.Listener { response ->
                    iVolley!!.onResponse(response.toString())
                    Log.d("Access token: ", response.toString())
                }, Response.ErrorListener { error -> iVolley!!.onResponse((error.message!!)) }) {

                override fun getBodyContentType(): String {
                    return "application/x-www-form-urlencoded; charset=UTF-8"
                }

                @Throws(AuthFailureError::class)
                override fun getHeaders(): Map<String, String> {
                    val credentials = "$SPOTIFY_CLIENT_ID:$SPOTIFY_CLIENT_SECRET"
                    val base64EncodedCredentials: String =
                        Base64.encodeToString(credentials.toByteArray(), Base64.NO_WRAP)

                    val headers: MutableMap<String, String> = HashMap()
                    headers["Authorization"] = "Basic $base64EncodedCredentials" // Header authorization parameter
                    //headers["-H Authorization"] = "Basic $base64EncodedCredentials" // Header authorization parameter
                    //headers["Content-Type"] = "application/json; charset=UTF-8"
                    return headers
                }

                override fun getParams(): MutableMap<String, String> {
                    val params = HashMap<String, String>()
                    params["grant-type"] = "client_credentials" // Request body parameter
                    //params["-d grant-type"] = "client_credentials"
                    return params
                }
            }

            queue?.add(postRequest)

<> P>任何解决这个问题的帮助都被理解为

身体参数->代码> GrANTHYTYPE 似乎中间有一个下划线而不是短线!“-”啊,那是我愚蠢的错误!谢谢,现在可以用了
curl -X "POST" -H "Authorization: Basic ZjM4ZjAw...WY0MzE=" -d grant_type=client_credentials https://accounts.spotify.com/api/token