从Spotify api获取访问令牌

时间:2015-10-08 11:49:42

标签: spotify

我正在尝试使用asp.net:https://accounts.spotify.com/api/token

从此端点获取访问令牌

我回来的令牌有Status = WaitingForActivation,Method =“{null}”,Result =“{Not yet computed}”。

在通过att Spotify Developer创建我的应用程序时,我将我的Redirect Uri称为http://localhost:59486/,这是我的Project Url。

我做错了什么?

我从https://hendrikbulens.wordpress.com/2015/01/07/c-and-the-spotify-web-api-part-i/

借用了这个方法
private async Task<string> GetAccessToken()
        {
            SpotifyToken token = new SpotifyToken();

            string postString = string.Format("grant_type=client_credentials");
            byte[] byteArray = Encoding.UTF8.GetBytes(postString);

            string url = "https://accounts.spotify.com/api/token";

            WebRequest request = WebRequest.Create(url);
            request.Method = "POST";
            request.Headers.Add("Authorization", "Basic YjlkZj****************************************jQ2YjM3MjE5MDE=");
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
            using (Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
                using (WebResponse response = await request.GetResponseAsync())
                {
                    using (Stream responseStream = response.GetResponseStream())
                    {
                        using (StreamReader reader = new StreamReader(responseStream))
                        {
                            string responseFromServer = reader.ReadToEnd();
                            token = JsonConvert.DeserializeObject<SpotifyToken>(responseFromServer);
                        }
                    }
                }
            }
            return token.access_token;
        }

编辑: 这是我的Http请求:

spotify.com/api/token HTTP/1.1
Authorization: Basic Yjlk....................5MDE=
Content-Type: application/x-www-form-urlencoded
Host: accounts.spotify.com
Content-Length: 29
Expect: 100-continue
Connection: Keep-Alive

grant_type=client_credentials

0 个答案:

没有答案
相关问题