【发布时间】:2019-11-30 19:44:41
【问题描述】:
我正在为我的 Spotify API 项目使用 johnnycrazy C#/.NET 包装器:https://johnnycrazy.github.io/SpotifyAPI-NET/
我正在尝试做的是编写一个端点来获取单个专辑。
我决定走 ClientCredentialsAuth 的路线,在那里我发出一个 POST 请求来处理获取令牌:https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Docs/docs/SpotifyWebAPI/auth.md#clientcredentialsauth
[HttpPost]
public async Task<IActionResult> GetAuth()
{
CredentialsAuth auth = new CredentialsAuth("_clientId", "_clientPass");
Token token = await auth.GetToken();
SpotifyWebAPI api = new SpotifyWebAPI() { TokenType = token.TokenType, AccessToken = token.AccessToken };
return Ok(api);
}
现在我需要编写一个使用它的端点,它将获得一张专辑。
这是获取专辑的假定用法:
FullAlbum album = _spotify.GetAlbum("5O7V8l4SeXTymVp3IesT9C");
Console.WriteLine(album.Name + "| Popularity: " + album.Popularity); //Display name and Popularity
但是我不清楚我应该如何使用这些自定义类编写一个完整的 GET 端点。到目前为止,我有这个:
private static SpotifyWebAPI _spotify;
// GET single Album
[HttpGet("{id}")]
public async Task<IActionResult> GetSingleAlbum(int id)
{
FullAlbum album = _spotify.GetAlbum("2KhkdN53S255mwgjrHUhho");
if (album == null)
{
return NotFound($"No album found with id of {id}");
}
return Ok(album);
}
任何能帮助我指明正确方向并让我走上正轨的方法都会有所帮助。提前谢谢!
【问题讨论】:
标签: c# asp.net-core spotify