projectgoav / E.Deezer

Unoffical asynchronous Deezer .NET API
17 stars 11 forks source link

Getting the last track #91

Closed b1sergiu closed 4 years ago

b1sergiu commented 4 years ago

Hello, I'm not sure if this is the best place to ask but I'm not sure how to get the details of the last played track. I saw the GetHistory() function however I'm not sure how to correctly use it.

projectgoav commented 4 years ago

Just to clarify, you're looking to get the last played tracks from your Deezer account?

Also, could you please tell me which version of E.Deezer you are using. Thanks!

b1sergiu commented 4 years ago

Yes, getting the last played track on an account. I'm using the latest Nuget version of the package.

projectgoav commented 4 years ago

In order to do this you're going to need to get yourself a Deezer OAuth access token from your user account. I wont go into detail how OAuth works or how to obtain them from Deezer as you can find all that information at the Deezer developer pages: https://developers.deezer.com.

You may need to register an account to view the documentation but in order to get access tokens you have to create an account anyway.

Once you a token you need to pass it to the library via the Login() method on a DeezerSession instance. Then you can use the method you specified in the initial question to get your last played tracks.

Keep in mind that the tokens can, and will, expire. When this happens any request you make, that requires the use of a token, will throw an exception allowing you to obtain a new token and pass it to this library.

Please let me know if this answers your question.

b1sergiu commented 4 years ago

I'm asking you about the usage of the function. How do I use the method to get the last track? What parameters do I need to use?

projectgoav commented 4 years ago

The 3 steps you need are below. Please note, I've just used Task methods but you might prefer to use .ContinueWith(...) or await

var deezer = DeezerSession.CreateNew();

deezer.Login(/* Your Access Token */)
      .Wait();

/* By default this method gets up-to the last 100. 
 * Specifying a count of 1 means to get the most recently played. */
var history = deezer.User.GetHistory(0, 1)
                         .Result;
b1sergiu commented 4 years ago

Alright, thanks for your help!