Getting Started
Adding SpotifyAPI-NET to your project
The library can be added to your project via the following methods:
Package Managers
- .NET CLI
- Package Manager
- Package Reference
dotnet add package SpotifyAPI.Web
# Optional Auth module, which includes an embedded HTTP Server for OAuth2
dotnet add package SpotifyAPI.Web.Auth
Install-Package SpotifyAPI.Web
# Optional Auth module, which includes an embedded HTTP Server for OAuth2
Install-Package SpotifyAPI.Web.Auth
<PackageReference Include="SpotifyAPI.Web" Version="6.2.2" />
<!-- Optional Auth module, which includes an embedded HTTP Server for OAuth2 -->
<PackageReference Include="SpotifyAPI.Web.Auth" Version="6.2.2" />
Add DLL Manually
You can also grab the latest compiled DLL from our GitHub Releases Page. It can be added to your project via Visual Studio or directly in your .csproj
:
<ItemGroup>
<Reference Include="SpotifyAPI.Web">
<HintPath>..\Dlls\SpotifyAPI.Web.dll</HintPath>
</Reference>
</ItemGroup>
Compile Yourself
git clone https://github.com/JohnnyCrazy/SpotifyAPI-NET.git
cd SpotifyAPI-NET
dotnet restore
dotnet build
ls -la SpotifyAPI.Web/bin/Debug/netstandard2.1/SpotifyAPI.Web.dll
First API Calls
You're now ready to issue your first calls to the Spotify API, a small console example:
using System;
using System.Threading.Tasks;
using SpotifyAPI.Web;
class Program
{
static async Task Main()
{
var spotify = new SpotifyClient("YourAccessToken");
var track = await spotify.Tracks.Get("1s6ux0lNiTziSrd7iUAADH");
Console.WriteLine(track.Name);
}
}
Notice that the spotify api does not allow unauthorized API access. Wondering where you should get an access token from? For a quick test, head over to the Spotify Developer Console and generate an access token with the required scopes! For a permanent solution, head over to the authentication guides.
There is no online documentation for every available API call, but XML inline docs are available:
All calls have the Spotify Web API documentation reference attached as a remark.
Query/Body Parameters
If an API endpoint has query or body parameters, a request model can be supplied to the method
// No optional or required query/body parameters
// The track ID is part of the request path --> it's not treated as query/body parameter
var track = await spotify.Tracks.Get("1s6ux0lNiTziSrd7iUAADH");
// Optional query/body parameter
var track = await spotify.Tracks.Get("1s6ux0lNiTziSrd7iUAADH", new TrackRequest{
Market = "DE"
});
// Sometimes, query/body parameters are also required!
var tracks = await spotify.Tracks.GetSeveral(new TracksRequest(new List<string> {
"1s6ux0lNiTziSrd7iUAADH",
"6YlOxoHWLjH6uVQvxUIUug"
}));
If a query/body parameter is required, it has to be supplied in the constructor of the request model. In the background, empty/null checks are also performed to make sure required parameters are not empty/null. If it is optional, it can be supplied as a property to the request model.
Guides
All other relevant topics are covered in the "Guides" and Authentication Guides section in the sidebar!