|
2 | 2 | id: getting_started |
3 | 3 | title: Getting Started |
4 | 4 | --- |
| 5 | + |
| 6 | +import InstallInstructions from '../src/install_instructions' |
| 7 | + |
| 8 | +## Adding SpotifyAPI-NET to your project |
| 9 | + |
| 10 | +The library can be added to your project via the following methods: |
| 11 | + |
| 12 | +### Package Managers |
| 13 | + |
| 14 | +<InstallInstructions /> |
| 15 | + |
| 16 | +### Add DLL Manually |
| 17 | + |
| 18 | +You can also grab the latest compiled DLL from our [GitHub Releases Page](https://github.com/johnnycrazy/spotifyapi-net/releases). It can be added to your project via Visual Studio or directly in your `.csproj`: |
| 19 | + |
| 20 | +```xml |
| 21 | +<ItemGroup> |
| 22 | + <Reference Include="SpotifyAPI.Web"> |
| 23 | + <HintPath>..\Dlls\SpotifyAPI.Web.dll</HintPath> |
| 24 | + </Reference> |
| 25 | +</ItemGroup> |
| 26 | +``` |
| 27 | + |
| 28 | +### Compile Yourself |
| 29 | + |
| 30 | +```sh |
| 31 | +git clone https://github.com/JohnnyCrazy/SpotifyAPI-NET.git |
| 32 | +cd SpotifyAPI-NET |
| 33 | +dotnet restore |
| 34 | +dotnet build |
| 35 | + |
| 36 | +ls -la SpotifyAPI.Web/bin/Debug/netstandard2.1/SpotifyAPI.Web.dll |
| 37 | +``` |
| 38 | + |
| 39 | +## First API Calls |
| 40 | + |
| 41 | +You're now ready to issue your first calls to the Spotify API, a small console example: |
| 42 | + |
| 43 | +```csharp |
| 44 | +using System; |
| 45 | +using SpotifyAPI.Web; |
| 46 | + |
| 47 | +class Program |
| 48 | +{ |
| 49 | + static async Task Main() |
| 50 | + { |
| 51 | + var spotify = new SpotifyClient("YourAccessToken"); |
| 52 | + |
| 53 | + var track = await spotify.Tracks.Get("1s6ux0lNiTziSrd7iUAADH"); |
| 54 | + Console.WriteLine(track.Name); |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +:::tip |
| 60 | +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](https://developer.spotify.com/console/get-album/) and generate an access token with the required scopes! For a permanent solution, head over to the [authentication guides](auth_introduction). |
| 61 | + |
| 62 | +::: |
| 63 | + |
| 64 | +There is no online documentation for every available API call, but XML inline docs are available: |
| 65 | + |
| 66 | +* [UserProfile](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/IUserProfileClient.cs) |
| 67 | +* [Browse](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/IBrowseClient.cs) |
| 68 | +* [Shows](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/IShowsClient.cs) |
| 69 | +* [Playlists](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/IPlaylistsClient.cs) |
| 70 | +* [Search](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/ISearchClient.cs) |
| 71 | +* [Follow](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/IFollowClient.cs) |
| 72 | +* [Tracks](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/ITracksClient.cs) |
| 73 | +* [Player](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/IPlayerClient.cs) |
| 74 | +* [Albums](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/IAlbumsClient.cs) |
| 75 | +* [Artists](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/IArtistsClient.cs) |
| 76 | +* [Personalization](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/IPersonalizationClient.cs) |
| 77 | +* [Episodes](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/IEpisodesClient.cs) |
| 78 | +* [Library](https://github.com/JohnnyCrazy/SpotifyAPI-NET/blob/master/SpotifyAPI.Web/Clients/Interfaces/ILibraryClient.cs) |
| 79 | + |
| 80 | +All calls have the [Spotify Web API documentation reference](https://developer.spotify.com/documentation/web-api/reference-beta/) attached as a remark. |
| 81 | + |
| 82 | + |
| 83 | +## Query/Body Parameters |
| 84 | + |
| 85 | +If an API endpoint has query or body parameters, a request model can be supplied to the method |
| 86 | + |
| 87 | +```csharp |
| 88 | +// No optional or required query/body parameters |
| 89 | +// The track ID is part of the request path --> it's not treated as query/body parameter |
| 90 | +var track = await spotify.Tracks.Get("1s6ux0lNiTziSrd7iUAADH"); |
| 91 | + |
| 92 | +// Optional query/body parameter |
| 93 | +var track = await spotify.Tracks.Get("1s6ux0lNiTziSrd7iUAADH", new TrackRequest{ |
| 94 | + Market = "DE" |
| 95 | +}); |
| 96 | + |
| 97 | +// Sometimes, query/body parameters are also required! |
| 98 | +var tracks = await spotify.Tracks.GetSeveral(new TracksRequest(new List<string> { |
| 99 | + "1s6ux0lNiTziSrd7iUAADH", |
| 100 | + "6YlOxoHWLjH6uVQvxUIUug" |
| 101 | +})); |
| 102 | +``` |
| 103 | + |
| 104 | +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. |
| 105 | + |
| 106 | +## Guides |
| 107 | + |
| 108 | +All other relevant topics are covered in the "Guides" and [Authentication Guides](auth_introduction) section in the sidebar! |
0 commit comments