Skip to content

MuHamza30/spotify-dotnet-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started with Spotify Web API

Introduction

You can use Spotify's Web API to discover music and podcasts, manage your Spotify library, control audio playback, and much more. Browse our available Web API endpoints using the sidebar at left, or via the navigation bar on top of this page on smaller screens.

In order to make successful Web API requests your app will need a valid access token. One can be obtained through OAuth 2.0.

The base URI for all Web API requests is https://api.spotify.com/v1.

Need help? See our Web API guides for more information, or visit the Spotify for Developers community forum to ask questions and connect with other developers.

Building

The generated code uses the Newtonsoft Json.NET NuGet Package. If the automatic NuGet package restore is enabled, these dependencies will be installed automatically. Therefore, you will need internet access for build.

  • Open the solution (SpotifyWebAPI.sln) file.

Invoke the build process using Ctrl + Shift + B shortcut key or using the Build menu as shown below.

The build process generates a portable class library, which can be used like a normal class library. More information on how to use can be found at the MSDN Portable Class Libraries documentation.

The supported version is .NET Standard 2.0. For checking compatibility of your .NET implementation with the generated library, click here.

Installation

The following section explains how to use the SpotifyWebAPI.Standard library in a new project.

1. Starting a new project

For starting a new project, right click on the current solution from the solution explorer and choose Add -> New Project.

Add a new project in Visual Studio

Next, choose Console Application, provide TestConsoleProject as the project name and click OK.

Create a new Console Application in Visual Studio

2. Set as startup project

The new console project is the entry point for the eventual execution. This requires us to set the TestConsoleProject as the start-up project. To do this, right-click on the TestConsoleProject and choose Set as StartUp Project form the context menu.

Adding a project reference

3. Add reference of the library project

In order to use the SpotifyWebAPI.Standard library in the new project, first we must add a project reference to the TestConsoleProject. First, right click on the References node in the solution explorer and click Add Reference...

Adding a project reference

Next, a window will be displayed where we must set the checkbox on SpotifyWebAPI.Standard and click OK. By doing this, we have added a reference of the SpotifyWebAPI.Standard project into the new TestConsoleProject.

Creating a project reference

4. Write sample code

Once the TestConsoleProject is created, a file named Program.cs will be visible in the solution explorer with an empty Main method. This is the entry point for the execution of the entire solution. Here, you can add code to initialize the client library and acquire the instance of a Controller class. Sample code to initialize the client library and using Controller methods is given in the subsequent sections.

Adding a project reference

Test the SDK

The generated SDK also contain one or more Tests, which are contained in the Tests project. In order to invoke these test cases, you will need NUnit 3.0 Test Adapter Extension for Visual Studio. Once the SDK is complied, the test cases should appear in the Test Explorer window. Here, you can click Run All to execute these test cases.

Initialize the API Client

Note: Documentation for the client can be found here.

The following parameters are configurable for the API Client:

Parameter Type Description
Environment Environment The API environment.
Default: Environment.Production
Timeout TimeSpan Http client timeout.
Default: TimeSpan.FromSeconds(100)
LogBuilder LogBuilder Represents the logging configuration builder for API calls
AuthorizationCodeAuth AuthorizationCodeAuth The Credentials Setter for OAuth 2 Authorization Code Grant

The API client can be initialized as follows:

SpotifyWebAPIClient client = new SpotifyWebAPIClient.Builder()
    .AuthorizationCodeAuth(
        new AuthorizationCodeAuthModel.Builder(
            "OAuthClientId",
            "OAuthClientSecret",
            "OAuthRedirectUri"
        )
        .OAuthScopes(
            new List<OAuthScopeEnum>
            {
                OAuthScopeEnum.AppRemoteControl,
                OAuthScopeEnum.PlaylistReadPrivate,
            })
        .Build())
    .Environment(SpotifyWebAPI.Standard.Environment.Production)
    .LoggingConfig(config => config
        .LogLevel(LogLevel.Information)
        .RequestConfig(reqConfig => reqConfig.Body(true))
        .ResponseConfig(respConfig => respConfig.Headers(true))
    )
    .Build();

Authorization

This API uses the following authentication schemes.

List of APIs

Classes Documentation

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages