0
votes

I am using the johnnycrazy C#/.NET wrapper for my Spotify API project: https://johnnycrazy.github.io/SpotifyAPI-NET/

What I am attempting to do is write an endpoint to get a single Album.

I've decided to go the route of ClientCredentialsAuth, where I make a POST request to handle getting the token: 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);
}

Now I need to write an endpoint that utilizes this, and that will get a single album.

This is the supposed usage for getting an album:

FullAlbum album = _spotify.GetAlbum("5O7V8l4SeXTymVp3IesT9C");
Console.WriteLine(album.Name + "| Popularity: " + album.Popularity); //Display name and Popularity

But It's just unclear to me as to how I'm supposed to write a complete GET endpoint, using these custom classes. So far, I have this:

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);
}

Any help to point me in the right direction, and get me on track, would be helpful. Thank you in advance!

1

1 Answers

0
votes

You've posted a link to documentation with good working code, but you seem to have totally disregarded it. You need to literally do something like:

CredentialsAuth auth = new CredentialsAuth(_clientId, _secretId);
Token token = await auth.GetToken();
SpotifyWebAPI api = new SpotifyWebAPI() {TokenType = token.TokenType, AccessToken = token.AccessToken};

FullAlbum = api.GetAlbum("2KhkdN53S255mwgjrHUhho");

if (album == null)
{
    return NotFound($"No album found with id of {id}");
}

return Ok(album);

In other words, you need to actually authorize the Spotify API class, and then make your actual request.