【发布时间】:2017-07-20 03:05:01
【问题描述】:
我正在尝试使用Spotify developer page 上的“客户端凭据流”下定义的过程请求一个 spotify 访问令牌,
这是我当前的实现(当前返回 http 400 错误):
using (var client = new HttpClient())
{
var requestBody = new StringContent(
"grant_type:client_credentials",
Encoding.UTF8,
"application/x-www-form-urlencoded");
var requestEncrypted = Convert.ToBase64String(
Encoding.UTF8.GetBytes(ClientId + ":" + ClientSecret));
client.DefaultRequestHeaders.Add(
"Authorization",
$"Basic {requestEncrypted}");
var tokenResult = await client.PostAsync(TokenEndpoint, requestBody);
}
我尝试了其他方法来格式化请求正文,包括 json(注意:将编码类型更改为“application/json”会导致 http 415 错误(不支持媒体)
【问题讨论】:
-
您的
TokenEndpoint值是多少? -
@ShaunLuttin 'accounts.spotify.com/api/token'
标签: c# asp.net asp.net-core spotify