Git Product home page Git Product logo

spotifywebapi's Introduction

Push NuGet version (SpotifyWebApi-Core) NuGet license

SpotifyWebApi - Core

A .net Core wrapper for the Spotify Web Api.

Nuget package

Installing the package is easy.

Using the package manager console:

PM> Install-Package SpotifyWebApi-Core

Using the dotnet CLI:

> dotnet add package SpotifyWebApi-Core

Getting an authentication token

Client credentials:

var token = ClientCredentials.GetToken(new AuthParameters
{
    ClientId = "clientId",
    ClientSecret = "clientSecret",
    Scopes = Scope.All,
});

Note: A client credentials token cannot access any personal data.
The Token class has a usefull property to check this: token.CanAccessPersonalData

Authorization code:

Start the authorization code process by retrieving the authentication url:

var state = Guid.NewGuid().ToString(); // Save this state because you must check it later

var parameters = new AuthParameters
{
    ClientId = "clientId",
    ClientSecret = "clientSecret",
    RedirectUri = "https://.../callback",
    Scopes = Scope.All,
    ShowDialog = true
};

var url = AuthorizationCode.GetUrl(parameters, state);

At this point you should start a webserver listening on the RedirectUri and the the client/user should login to Spotify.
The webserver should expect the following query parameters: ?code=code&state=state&error=error

// The retreived callback:
var retrievedState = "retrievedState";
var retrievedCode = "code";
var retreivedError = "";

if (state != retrievedState)
{
    throw new Exception("State did not match!");
}

var token = AuthorizationCode.ProcessCallback(parameters, retrievedCode, retreivedError);

// Use the api with access to personal data.
var api = new SpotifyWebApi(token);
var me = await api.UserProfile.GetMe();

A token received with the AuthorizationCode can also be refreshed:

// Refresh a token when its expired
if (token.IsExpired)
{
    token = AuthorizationCode.RefreshToken(parameters, token);
}

Using the api

After a token has been retrieved, we can use the api:

Getting a playlist and the playlist tracks:

ISpotifyWebApi api = new SpotifyWebApi(token);

var playlist = await spotify.Playlist.GetPlaylist(id);
var tracks = await spotify.Playlist.GetPlaylistTracks(id);

TODO:

  • Add documentation
  • Add api examples
  • Implement more endpoints

spotifywebapi's People

Contributors

albarker avatar daveowenatl avatar dependabot[bot] avatar ivandrofly avatar pimmerks avatar stevenaleong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spotifywebapi's Issues

Support .NET Core 2.0

My project is targeting .NET Core 2.0. I was going to give your wrapper a try, but it seems you've only got support for .NET 4.7.

Hopefully you can add this to your to-do list ๐Ÿ‘

Add all models

  • album object (full)
  • album object (simplified)
  • artist object (full)
  • artist object (simplified)
  • audio features object
  • category object
  • copyright object
  • cursor object
  • error object
  • external ID object
  • external URL object
  • followers object
  • image object
  • paging object
  • cursor-based paging object
  • playlist object (full)
  • playlist object (simplified)
  • playlist track object
  • recommendations object
  • recommendations seed object
  • saved track object
  • saved album object
  • track object (full)
  • track object (simplified)
  • track link
  • user object (private)
  • user object (public)

Make remaining api's available.

TODO:

  • Album
  • Artist
  • Browse
  • Follow
  • Personalization
  • Player - Partially done.
  • Playlist
  • Search - In beta
  • Track
  • UserLibrary
  • UserProfile

Bug In Scopes Enum

In the Scopes flags enum UserLibraryModify should be 256 but is instead given the value 265.

Implement all api's

  • Albums
  • Artists
  • Browse
  • Episodes
  • Follow
  • Library
  • Personalization
  • Player
  • Playlists
  • Search
  • Shows
  • Tracks
  • Users Profile

Tokens do not seem to refresh automatically.

The Token's TokenGenerated property is set in the constructor, but the property is not serializable to json.

When deserializing a Token from json, the property will have the current date instead of the date it was actually generated. This causes the IsExpired flag to be false, when it should be true.

Playlist crashes if there is songs from the local disk

If there is any local songs that don't exist in Spotify's library in a playlist it will crash on trying to get that playlist. This is caused by the track not having an URI. Error: Newtonsoft.Json.JsonSerializationException: 'Error converting value "[name of local song]" to type 'SpotifyWebApi.Model.Uri.SpotifyUri'. Happens when calling "Playlist.GetPlaylistTracks".

GetMyPlaylists doesnt work

The GetMyPlaylists function doesnt work correctly. Ive got the following error message:
Error converting value "spotify:playlist:3G1AlVTYExPN28BlCxf8GD" to type 'SpotifyWebApi.Model.Uri.SpotifyUri'. Path 'items[0].uri', line 34, position 53.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.