项目作者: 0xNF

项目描述 :
Spotify Web API wrapper for Dot Net Standard, for use in UWP and .NET Core
高级语言: C#
项目地址: git://github.com/0xNF/DotNetStandardSpotifyWebApi.git
创建时间: 2017-05-25T21:01:58Z
项目社区:https://github.com/0xNF/DotNetStandardSpotifyWebApi

开源协议:MIT License

下载


.NET Standard Spotify Web API

Available on NuGet at
https://www.nuget.org/packages/DotNetStandardSpotifyWebApi/0.1.0

A C# wrapper for the Spotify Web API written for .Net Standard (v1.4).

Compatible with .NET Core, ASP.NET Core, and UWP.

91% Complete

Todo:

  • Implement the Search and Playlist Track Remove endpoints
  • Make Authorization easier

Available Endpoints

Currently Implements the following endpoints:

The following endpoints are not yet implemeted:

Examples:

Authenticating:
  1. using DotNetStandardSpotifyWebApi.Authorization;
  2. string Client_Id = "<your client id>";
  3. string Client_Secret = "<your client secret>";
  4. string Redirect_URI = "<your redirect uri>";
  5. List<SpotifyScopeEnum> Scopes = new List<SpotifyScopEnum>(){
  6. SpotifyScopeEnum.PLAYLIST_READ_PRIVATE,
  7. SpotifyScopeEnum.STREAMING,
  8. SpotifyScopeEnum.USER_LIBRARY_MODIFY,
  9. };
  10. //Use the AuthorizationInProgress to send the redirect url to spotify and get user authentication
  11. AuthorizationInProgress authProg = AuthorizationCodeFlow.GetAuthStateAndRedirect(Client_Id, Redirect_URI, Scopes);
  12. //Using an OAuth token taken from the redirected url, exchange for a full authenticated credentials object
  13. OAuthCredentials token = await AuthorizationCodeFlow.GetSpotifyTokenCredentials(OAuthToken, Client_Id, Client_Secret, Redirect_URI);
  14. //Console.WriteLine(token.Access_token);
  15. //> <access_token>
  16. //Console.WriteLine(token.Refresh_token);
  17. //> <refresh_token>
  18. //Console.WriteLine(token.Expires_in);
  19. //> <expires_in>

Refreshing an access token:

  1. //With a refresh token
  2. string refresh_token = "<your refresh token>";
  3. OAuthCredentials refreshed = AuthorizationCodeFlow.RefreshAccessToken(refresh_token, Client_Id, Client_Secret);
  4. //With an OAuthCredentials
  5. OAuthCredentials creds = <Credentials Object with expired access token>;
  6. creds = AuthorizationCodeFlow.RefreshAccessToken(expired, Client_Id, Client_Secret);

Getting Spotify Objects

Current User
  1. using DotNetStandardSpotifyWebApi.ObjectModel;
  2. OAuthCredentials Creds = <...>;
  3. User me = await Endpoints.GetCurrentUser(Creds.Access_token);
Getting a Track
  1. Track YouStreet = await Endpoints.GetATrack(Creds.Access_token, "7o5dTvQk2Nia65kASf2Ezo");

Getting a track with from a specific market. Used in track re-linking

  1. Track DareYori = await Endpoints.GetATrack(Creds.Access_token, "4FwzvpVpgzI3tj9FHVPJQh", market="JP");
Getting a Playlist
  1. User currentUser = <...>;
  2. string PlaylistToGet = "5XDtox3aWN1U8hczfRZuJm";
  3. Playlist Lounge = await Endpoints.GetAPlaylist(Creds.Access_token, currentUser.Id, PlaylistToGet);

For more complete examples, see the ObjectModelTests.cs file.