mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 14:46:26 +00:00
Updated docs & Updated deps, should fix #304
This commit is contained in:
parent
467984c6f8
commit
2f8197359d
3
.gitignore
vendored
3
.gitignore
vendored
@ -111,3 +111,6 @@ UpgradeLog*.XML
|
|||||||
# NuGet
|
# NuGet
|
||||||
/packages/
|
/packages/
|
||||||
*.nupkg
|
*.nupkg
|
||||||
|
|
||||||
|
# Idea jetbrains
|
||||||
|
.idea/
|
||||||
|
@ -1,171 +0,0 @@
|
|||||||
# Getting started
|
|
||||||
|
|
||||||
This API provides some access to the local running Spotify-Client (Windows only).
|
|
||||||
You can fetch details for the current track, play/pause, skip/previous track and
|
|
||||||
get notified on various events.
|
|
||||||
|
|
||||||
**NOTE:** This API is unofficial, things may break in the future and there is no
|
|
||||||
guarantee everything works out of the box.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## First steps
|
|
||||||
|
|
||||||
**Imports**
|
|
||||||
So after you added the API to your project, you may want to add following imports to your files:
|
|
||||||
|
|
||||||
```cs
|
|
||||||
using SpotifyAPI.Local; //Base Namespace
|
|
||||||
using SpotifyAPI.Local.Enums; //Enums
|
|
||||||
using SpotifyAPI.Local.Models; //Models for the JSON-responses
|
|
||||||
```
|
|
||||||
|
|
||||||
**Basic-Usage**
|
|
||||||
Now you can actually start fetching infos from your spotify client, just create a new Instance of SpotifyLocalAPI:
|
|
||||||
```cs
|
|
||||||
private static SpotifyLocalAPI _spotify;
|
|
||||||
|
|
||||||
public static void Main(String[] args)
|
|
||||||
{
|
|
||||||
_spotify = new SpotifyLocalAPI();
|
|
||||||
if (!SpotifyLocalAPI.IsSpotifyRunning())
|
|
||||||
return; //Make sure the spotify client is running
|
|
||||||
if (!SpotifyLocalAPI.IsSpotifyWebHelperRunning())
|
|
||||||
return; //Make sure the WebHelper is running
|
|
||||||
|
|
||||||
if(!_spotify.Connect())
|
|
||||||
return; //We need to call Connect before fetching infos, this will handle Auth stuff
|
|
||||||
|
|
||||||
StatusResponse status = _spotify.GetStatus(); //status contains infos
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuration
|
|
||||||
|
|
||||||
Different spotify versions often require different configuration. Some versions run their web-helper on port `4371`, others on `4381` or `4380`. Also, some use `https`, and others use `http`. You can use `SpotifyLocalAPIConfig` to configure the API:
|
|
||||||
|
|
||||||
```cs
|
|
||||||
_spotify = new SpotifyLocalAPI(new SpotifyLocalAPIConfig
|
|
||||||
{
|
|
||||||
Port = 4371,
|
|
||||||
HostUrl = "https://127.0.0.1"
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
it's also possible to change the current `UserAgent` string, which is needed if the library wasn't updated for some time. In this case, you should first make an unauthenticated call with `spotify.GetStatus()`, receive the current spotify version, and update the config afterwards:
|
|
||||||
|
|
||||||
```cs
|
|
||||||
var config = new SpotifyLocalAPIConfig { Port = 4371, HostUrl = "https://127.0.0.1" });
|
|
||||||
_spotify = new SpotifyLocalAPI(config);
|
|
||||||
|
|
||||||
var status = _spotify.GetStatus();
|
|
||||||
config.UserAgent = status.ClientVersion;
|
|
||||||
|
|
||||||
// Now you should call auth stuff, like "_spotify.Connect()"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Proxy Settings
|
|
||||||
|
|
||||||
You can forward your proxy settings to the local api by using a field in the `SpotifyLocalAPIConfig`.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
_spotify = new SpotifyLocalAPI(new SpotifyLocalAPIConfig
|
|
||||||
{
|
|
||||||
ProxyConfig = new ProxyConfig() {
|
|
||||||
Host = "127.0.0.1",
|
|
||||||
Port = 8080
|
|
||||||
// Additional values like Username and Password are available
|
|
||||||
}
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Anti-Virus Blocking Response
|
|
||||||
|
|
||||||
Some Anti-Virus Software blocks the response from spotify due wrong headers.
|
|
||||||
Currently, it's confirmed for AVG's LinkScanner and Bitdefender.
|
|
||||||
Adding `http://SpotifyAPI.spotilocal.com:4380` to the URL-Exceptions seems to fix it for most users.
|
|
||||||
More infos can be found [here](https://github.com/JohnnyCrazy/SpotifyAPI-NET/issues/51)
|
|
||||||
|
|
||||||
## Client Status
|
|
||||||
|
|
||||||
Calling `_spotify.GetStatus()` after connecting returns the following `StatusResponse`:
|
|
||||||
|
|
||||||
```
|
|
||||||
public int Version { get; set; }
|
|
||||||
|
|
||||||
public string ClientVersion { get; set; }
|
|
||||||
|
|
||||||
public bool Playing { get; set; }
|
|
||||||
|
|
||||||
public bool Shuffle { get; set; }
|
|
||||||
|
|
||||||
public bool Repeat { get; set; }
|
|
||||||
|
|
||||||
public bool PlayEnabled { get; set; }
|
|
||||||
|
|
||||||
public bool PrevEnabled { get; set; }
|
|
||||||
|
|
||||||
public bool NextEnabled { get; set; }
|
|
||||||
|
|
||||||
public Track Track { get; set; }
|
|
||||||
|
|
||||||
public double PlayingPosition { get; set; }
|
|
||||||
|
|
||||||
public int ServerTime { get; set; }
|
|
||||||
|
|
||||||
public double Volume { get; set; }
|
|
||||||
|
|
||||||
public bool Online { get; set; }
|
|
||||||
|
|
||||||
public bool Running { get; set; }
|
|
||||||
```
|
|
||||||
|
|
||||||
Most of the properties are self-explanatory, some notes:
|
|
||||||
|
|
||||||
* `Shuffle` and `Repeat` currently always return `false`
|
|
||||||
|
|
||||||
## Current Track
|
|
||||||
|
|
||||||
The current Track can be fetched via `_spotify.GetStatus().Track` and contains following properties/methods:
|
|
||||||
|
|
||||||
* `TrackResource` - `SpotifyResource` which contains Track `Name` and `Uri`
|
|
||||||
* `AlbumResource` - `SpotifyResource` which contains Album `Name` and `Uri`
|
|
||||||
* `ArtistResource` - `SpotifyResource` which contains Artist `Name` and `Uri` (Only the main artist will be listed)
|
|
||||||
* `IsAd()` will check whether the current track is an AD
|
|
||||||
* Various methods for getting the album art:
|
|
||||||
* `string GetAlbumArtUrl(AlbumArtSize size)`
|
|
||||||
* `Task<Bitmap> GetAlbumArtAsync(AlbumArtSize size)`
|
|
||||||
* `Bitmap GetAlbumArt(AlbumArtSize size)`
|
|
||||||
* `Task<byte[]> GetAlbumArtAsByteArrayAsync(AlbumArtSize size)`
|
|
||||||
* `byte[] GetAlbumArtAsByteArray(AlbumArtSize size)`
|
|
||||||
|
|
||||||
## Events
|
|
||||||
|
|
||||||
To receive events, make sure you listen for them `_spotify.ListenForEvents = true;`
|
|
||||||
You can set a `SynchronizingObject`, then the events will be called on the specific context
|
|
||||||
|
|
||||||
Following events can be overriden:
|
|
||||||
|
|
||||||
* `OnPlayStateChange` - triggers when the player changes from `play` to `pause` and vice versa
|
|
||||||
* `OnTrackChange` - triggers when a new track will be played
|
|
||||||
* `OnTrackTimeChange` - triggers when a track is playing and track-time changes
|
|
||||||
* `OnVolumeChange` - triggeres when the internal volume of spotify changes
|
|
||||||
|
|
||||||
## Methods
|
|
||||||
|
|
||||||
Furthermore, following methods are available:
|
|
||||||
|
|
||||||
* `void Mute()` - will mute the Spotify client via WindowsAPI
|
|
||||||
* `void UnMute()` - will unmute the Spotify client via WindowsAPI
|
|
||||||
* `bool IsSpotifyMuted()` - will return wether the Spotify client is muted
|
|
||||||
* `void SetSpotifyVolume(float volume = 100)` - sets the windows volume of spotify (0 - 100)
|
|
||||||
* `float GetSpotifyVolume()` - returns the windows volume of spotify (0 - 100)
|
|
||||||
* `void Pause()` - will pause spotify's playback
|
|
||||||
* `void Play()` - will resume spotify's playback
|
|
||||||
* `void PlayURL(string uri, string context = "")` - will play a spotify URI (track/album/playlist) in the specifc context (can be a album/playlist URI)
|
|
||||||
* `void Skip()` - will skip the track via an emulated media key
|
|
||||||
* `void Previous()` - will play the previous track via an emulated media key
|
|
||||||
* `bool IsSpotifyRunning()` - returns true if a spotify client instance is running, false if not
|
|
||||||
* `bool IsSpotifyWebHelperRunning()` - returns true if a spotify web-helper instance is running, false if not
|
|
||||||
* `void RunSpotify()` - will attempt to start a Spotify instance
|
|
||||||
* `void RunSpotifyWebHelper()` - will attempt to start a Spotify web-helper instance
|
|
@ -1,7 +1,7 @@
|
|||||||
##GetAlbumTracks
|
##GetAlbumTracks
|
||||||
> Get Spotify catalog information about an album's tracks. Optional parameters can be used to limit the number of tracks returned.
|
> Get Spotify catalog information about an album's tracks. Optional parameters can be used to limit the number of tracks returned.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -24,7 +24,7 @@ Console.WriteLine(tracks.Total.ToString()) //Display total album track count
|
|||||||
##GetAlbum
|
##GetAlbum
|
||||||
> Get Spotify catalog information for a single album.
|
> Get Spotify catalog information for a single album.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -43,7 +43,7 @@ Console.WriteLine(album.Name + "| Popularity: " + album.Popularity); //Display n
|
|||||||
##GetSeveralAlbums
|
##GetSeveralAlbums
|
||||||
> Get Spotify catalog information for multiple albums identified by their Spotify IDs.
|
> Get Spotify catalog information for multiple albums identified by their Spotify IDs.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
> Get Spotify catalog information for a single artist identified by their unique Spotify ID.
|
> Get Spotify catalog information for a single artist identified by their unique Spotify ID.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -20,7 +20,7 @@ Console.WriteLine()
|
|||||||
##GetRelatedArtists
|
##GetRelatedArtists
|
||||||
> Get Spotify catalog information about artists similar to a given artist. Similarity is based on analysis of the Spotify community's listening history.
|
> Get Spotify catalog information about artists similar to a given artist. Similarity is based on analysis of the Spotify community's listening history.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -38,7 +38,7 @@ Console.WriteLine(artists.Artists[0].Name);
|
|||||||
##GetArtistsTopTracks
|
##GetArtistsTopTracks
|
||||||
> Get Spotify catalog information about an artist's top tracks by country.
|
> Get Spotify catalog information about an artist's top tracks by country.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -57,7 +57,7 @@ Console.WriteLine(tracks.Tracks.Count); //How many tracks did we get?
|
|||||||
##GetArtistsAlbums
|
##GetArtistsAlbums
|
||||||
> Get Spotify catalog information about an artist's albums. Optional parameters can be specified in the query string to filter and sort the response.
|
> Get Spotify catalog information about an artist's albums. Optional parameters can be specified in the query string to filter and sort the response.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -79,7 +79,7 @@ albums.Items.ForEach(album => Console.WriteLine(album.Name));
|
|||||||
##GetSeveralArtists
|
##GetSeveralArtists
|
||||||
> Get Spotify catalog information for several artists based on their Spotify IDs.
|
> Get Spotify catalog information for several artists based on their Spotify IDs.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
|
@ -1,193 +1,94 @@
|
|||||||
#Auth-Methods
|
#Auth-Methods
|
||||||
|
|
||||||
Before you can use the Web API full functional, you need the user to authenticate your Application.
|
Before you can use the Web API full functional, you need the user to authenticate your Application.
|
||||||
If you want to know more, you can read to the whole auth-process [here](https://developer.spotify.com/web-api/authorization-guide/).
|
If you want to know more, you can read to the whole auth-process [here](https://developer.spotify.com/web-api/authorization-guide/).
|
||||||
|
|
||||||
Before you start, you need to create a Application at Spotify: [Your Applications](https://developer.spotify.com/my-applications/#!/applications)
|
Before you start, install `SpotifyAPI.Web.Auth` and create an application at Spotify: [Your Applications](https://developer.spotify.com/my-applications/#!/applications)
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
After you created your Application, you will have following important values:
|
After you created your Application, you will have following important values:
|
||||||
>**Client_Id** This is your client_id, you don't have to hide it
|
>**Client_Id**: This is your client_id, you don't have to hide it
|
||||||
>**Client_Secret** Never use this in one of your client-side apps!! Keep it secret!
|
>**Client_Secret**: Never use this in one of your client-side apps!! Keep it secret!
|
||||||
>**Redirect URIs** Add "http://localhost", if you want full support for this API
|
>**Redirect URIs**: Add "http://localhost", if you want full support for this API
|
||||||
|
|
||||||
Now you can start with the User-authentication, Spotify provides 3 ways:
|
Now you can start with the User-authentication, Spotify provides 3 ways:
|
||||||
|
|
||||||
* [ImplicitGrantAuth](/SpotifyWebAPI/auth#implicitgrantauth) (**Recommended**, no server-side code needed)
|
* [ImplicitGrantAuth](/SpotifyWebAPI/auth#implicitgrantauth)
|
||||||
|
|
||||||
* [AutorizationCodeAuth](/SpotifyWebAPI/auth#autorizationcodeauth) (Not Recommended, Server-side code needed, else it's unsecure)
|
* [AutorizationCodeAuth](/SpotifyWebAPI/auth#autorizationcodeauth)
|
||||||
|
|
||||||
* [ClientCredentialsAuth](/SpotifyWebAPI/auth#clientcredentialsauth) (Not Recommended, Server-side code needed, else it's unsecure)
|
* [ClientCredentialsAuth](/SpotifyWebAPI/auth#clientcredentialsauth)
|
||||||
|
|
||||||
**Note:** I would recommend a little PHP Script, which will exchange the Keys using AutorizationCodeAuth.
|
## Notes
|
||||||
When using ImplicitGrantAuth, another user could abuse the "localhost" RedirectUri by creating a "fake"-app which uses your ClientId.
|
|
||||||
|
Generally, if you're developing a 100% client-side application, no auth mechanism is totally secure. `AutorizationCodeAuth` and `ClientCredentialsAuth` require your clients to know the `client_secret`, which should be kept secret. For `ImplicitGrantAuth` to work, `http://localhost` needs to be added to the redirect uris of your spotify application. Since `localhost` is not a controlled domain by you, everybody is able to generate API-Keys. However, it is still the best option of all 3.
|
||||||
|
|
||||||
Overview:
|
Overview:
|
||||||
![Overview](http://i.imgur.com/uf3ahTl.png)
|
![Overview](http://i.imgur.com/uf3ahTl.png)
|
||||||
|
|
||||||
After implementing one of the provided auth-methods, you can start doing requests with the token you get from one of the auth-methods
|
After implementing one of the provided auth-methods, you can start doing requests with the token you get from one of the auth-methods.
|
||||||
|
|
||||||
##ImplicitGrantAuth
|
##ImplicitGrantAuth
|
||||||
|
|
||||||
This way is **recommended** and the only auth-process, which does not need a server-side exchange of keys. With this approach, you directly get a Token object after the user authed your application.
|
With this approach, you directly get a Token object after the user authed your application.
|
||||||
You won't be able to refresh the token. If you want to use the internal Http server, please add "http://localhost" to your application redirects.
|
You won't be able to refresh the token. If you want to use the internal Http server, make sure the redirect URI is in your spotify application redirects.
|
||||||
|
|
||||||
More info: [here](https://developer.spotify.com/web-api/authorization-guide/#implicit_grant_flow)
|
More info: [here](https://developer.spotify.com/documentation/general/guides/authorization-guide/#implicit-grant-flow)
|
||||||
|
|
||||||
For this kind of authentication, there is also a `WebAPIFactory`, it's easier to use and uses an async method:
|
```c#
|
||||||
```
|
|
||||||
static async void Main(string[] args)
|
static async void Main(string[] args)
|
||||||
{
|
{
|
||||||
WebAPIFactory webApiFactory = new WebAPIFactory(
|
ImplicitGrantAuth auth =
|
||||||
"http://localhost",
|
new ImplicitGrantAuth(_clientId, "http://localhost:4002", "http://localhost:4002", Scope.UserReadPrivate);
|
||||||
8000,
|
auth.AuthReceived += async (sender, payload) =>
|
||||||
"XXXXXXXXXXXXXXXX",
|
|
||||||
Scope.UserReadPrivate,
|
|
||||||
TimeSpan.FromSeconds(20)
|
|
||||||
);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//This will open the user's browser and returns once
|
|
||||||
//the user is authorized.
|
|
||||||
_spotify = await webApiFactory.GetWebApi();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_spotify == null)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
The old way:
|
|
||||||
```
|
|
||||||
static ImplicitGrantAuth auth;
|
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
|
||||||
//Create the auth object
|
|
||||||
auth = new ImplicitGrantAuth()
|
|
||||||
{
|
{
|
||||||
//Your client Id
|
auth.Stop(); // `sender` is also the auth instance
|
||||||
ClientId = "XXXXXXXXXXXXXXXX",
|
SpotifyWebAPI api = new SpotifyWebAPI() {TokenType = payload.TokenType, AccessToken = payload.AccessToken};
|
||||||
//Set this to localhost if you want to use the built-in HTTP Server
|
// Do requests with API client
|
||||||
RedirectUri = "http://localhost",
|
|
||||||
//How many permissions we need?
|
|
||||||
Scope = Scope.UserReadPrivate,
|
|
||||||
};
|
};
|
||||||
//Start the internal http server
|
auth.Start(); // Starts an internal HTTP Server
|
||||||
auth.StartHttpServer();
|
auth.OpenBrowser();
|
||||||
//When we got our response
|
|
||||||
auth.OnResponseReceivedEvent += auth_OnResponseReceivedEvent;
|
|
||||||
//Start
|
|
||||||
auth.DoAuth();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void auth_OnResponseReceivedEvent(Token token, string state, string error)
|
|
||||||
{
|
|
||||||
var spotify = new SpotifyWebApiClass()
|
|
||||||
{
|
|
||||||
TokenType = token.TokenType,
|
|
||||||
AccessToken = token.AccessToken
|
|
||||||
};
|
|
||||||
//We can now make calls with the token object
|
|
||||||
|
|
||||||
//stop the http server
|
|
||||||
auth.StopHttpServer();
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
##AutorizationCodeAuth
|
##AutorizationCodeAuth
|
||||||
|
|
||||||
This way is **not recommended** and requires server-side code to run securely.
|
This way is **not recommended** and requires server-side code to run securely.
|
||||||
With this approach, you first get a code which you need to trade against the access-token.
|
With this approach, you first get a code which you need to trade against the access-token.
|
||||||
In this exchange you need to provide your Client-Secret and because of that it's not recommended.
|
In this exchange you need to provide your Client-Secret and because of that it's not recommended.
|
||||||
(But you can e.g exchange to codes via a PHP Script)
|
|
||||||
A good thing about this method: You can always refresh your token, without having the user to auth it again
|
A good thing about this method: You can always refresh your token, without having the user to auth it again
|
||||||
|
|
||||||
More info: [here](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow)
|
More info: [here](https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow)
|
||||||
|
|
||||||
```
|
```c#
|
||||||
static AutorizationCodeAuth auth;
|
static async void Main(string[] args)
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
{
|
||||||
//Create the auth object
|
AuthorizationCodeAuth auth =
|
||||||
auth = new AutorizationCodeAuth()
|
new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
|
||||||
|
Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative);
|
||||||
|
auth.AuthReceived += async (sender, payload) =>
|
||||||
{
|
{
|
||||||
//Your client Id
|
auth.Stop();
|
||||||
ClientId = "XXXXXXXXXXXXXXX",
|
Token token = await auth.ExchangeCode(payload.Code);
|
||||||
//Set this to localhost if you want to use the built-in HTTP Server
|
SpotifyWebAPI api = new SpotifyWebAPI() {TokenType = token.TokenType, AccessToken = token.AccessToken};
|
||||||
RedirectUri = "http://localhost",
|
// Do requests with API client
|
||||||
//How many permissions we need?
|
|
||||||
Scope = Scope.UserReadPrivate,
|
|
||||||
};
|
};
|
||||||
//This will be called, if the user cancled/accept the auth-request
|
auth.Start(); // Starts an internal HTTP Server
|
||||||
auth.OnResponseReceivedEvent += auth_OnResponseReceivedEvent;
|
auth.OpenBrowser();
|
||||||
//a local HTTP Server will be started (Needed for the response)
|
|
||||||
auth.StartHttpServer();
|
|
||||||
//This will open the spotify auth-page. The user can decline/accept the request
|
|
||||||
auth.DoAuth();
|
|
||||||
|
|
||||||
Thread.Sleep(60000);
|
|
||||||
auth.StopHttpServer();
|
|
||||||
Console.WriteLine("Too long, didnt respond, exiting now...");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void auth_OnResponseReceivedEvent(AutorizationCodeAuthResponse response)
|
|
||||||
{
|
|
||||||
|
|
||||||
//NEVER DO THIS! You would need to provide the ClientSecret.
|
|
||||||
//You would need to do it e.g via a PHP-Script.
|
|
||||||
Token token = auth.ExchangeAuthCode(response.Code, "XXXXXXXXXXX");
|
|
||||||
|
|
||||||
var spotify = new SpotifyWebApiClass()
|
|
||||||
{
|
|
||||||
TokenType = token.TokenType,
|
|
||||||
AccessToken = token.AccessToken
|
|
||||||
};
|
|
||||||
|
|
||||||
//With the token object, you can now make API calls
|
|
||||||
|
|
||||||
//Stop the HTTP Server, done.
|
|
||||||
auth.StopHttpServer();
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
##ClientCredentialsAuth
|
##ClientCredentialsAuth
|
||||||
|
|
||||||
This way is **not recommended** and requires server-side code to run securely.
|
With this approach, you make a POST Request with a base64 encoded string (consists of ClientId + ClientSecret). You will directly get the token (Without a local HTTP Server), but it will expire and can't be refreshed.
|
||||||
With this approach, you make a POST Request with a base64 encoded string (consists of ClientId + ClientSecret). You will directly get the token (Without a local HTTP Server), but it will expire and can't be refreshed.
|
If you want to use it securely, you would need to do it all server-side.
|
||||||
If you want to use it securely, you would need to do it all server-side.
|
|
||||||
**NOTE:** You will only be able to query non-user-related information e.g search for a Track.
|
**NOTE:** You will only be able to query non-user-related information e.g search for a Track.
|
||||||
|
|
||||||
More info: [here](https://developer.spotify.com/web-api/authorization-guide/#client_credentials_flow)
|
More info: [here](https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow)
|
||||||
|
|
||||||
|
```c#
|
||||||
|
CredentialsAuth auth = new CredentialsAuth(_clientId, _secretId);
|
||||||
|
Token token = await auth.GetToken();
|
||||||
|
SpotifyWebAPI api = new SpotifyWebAPI() {TokenType = token.TokenType, AccessToken = token.AccessToken};
|
||||||
```
|
```
|
||||||
static ClientCredentialsAuth auth;
|
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
|
||||||
//Create the auth object
|
|
||||||
auth = new ClientCredentialsAuth()
|
|
||||||
{
|
|
||||||
//Your client Id
|
|
||||||
ClientId = "XXXXXXXXXXXXXXX",
|
|
||||||
//Your client secret UNSECURE!!
|
|
||||||
ClientSecret = "XXXXXXXXXXXX",
|
|
||||||
//How many permissions we need?
|
|
||||||
Scope = Scope.UserReadPrivate,
|
|
||||||
};
|
|
||||||
//With this token object, we now can make calls
|
|
||||||
Token token = auth.DoAuth();
|
|
||||||
var spotify = new SpotifyWebApiClass()
|
|
||||||
{
|
|
||||||
TokenType = token.TokenType,
|
|
||||||
AccessToken = token.AccessToken,
|
|
||||||
UseAuth = false
|
|
||||||
};
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#Scopes
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Get a list of Spotify featured playlists (shown, for example, on a Spotify player’s “Browse” tab).
|
> Get a list of Spotify featured playlists (shown, for example, on a Spotify player’s “Browse” tab).
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -26,7 +26,7 @@ playlists.Playlists.Items.ForEach(playlist => Console.WriteLine(playlist.Name));
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Get a list of new album releases featured in Spotify (shown, for example, on a Spotify player’s “Browse” tab).
|
> Get a list of new album releases featured in Spotify (shown, for example, on a Spotify player’s “Browse” tab).
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -47,7 +47,7 @@ newAlbums.Albums.Items.ForEach(album => Console.WriteLine(album.Name));
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Get a list of categories used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
|
> Get a list of categories used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -69,7 +69,7 @@ categoryList.Categories.Items.ForEach(category => Console.WriteLine(category.Nam
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Get a single category used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
|
> Get a single category used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -90,7 +90,7 @@ Console.WriteLine(cat.Name);
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Get a list of Spotify playlists tagged with a particular category.
|
> Get a list of Spotify playlists tagged with a particular category.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Add the current user as a follower of one or more artists or other Spotify users.
|
> Add the current user as a follower of one or more artists or other Spotify users.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -23,7 +23,7 @@ ErrorResponse response = _spotify.Follow(FollowType.User, "1122095781");
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Remove the current user as a follower of one or more artists or other Spotify users.
|
> Remove the current user as a follower of one or more artists or other Spotify users.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -44,7 +44,7 @@ ErrorResponse response = _spotify.Unfollow(FollowType.User, "1122095781");
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Check to see if the current user is following one or more artists or other Spotify users.
|
> Check to see if the current user is following one or more artists or other Spotify users.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -65,7 +65,7 @@ Console.WriteLine(response.List[0] ? "Yis!" : "No :(");
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Add the current user as a follower of a playlist.
|
> Add the current user as a follower of a playlist.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -87,7 +87,7 @@ if(!response.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Remove the current user as a follower of a playlist.
|
> Remove the current user as a follower of a playlist.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -108,7 +108,7 @@ if(!response.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Check to see if one or more Spotify users are following a specified playlist.
|
> Check to see if one or more Spotify users are following a specified playlist.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Save one or more tracks to the current user’s “Your Music” library.
|
> Save one or more tracks to the current user’s “Your Music” library.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -22,7 +22,7 @@ if(!response.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Save one track to the current user’s “Your Music” library.
|
> Save one track to the current user’s “Your Music” library.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -42,7 +42,7 @@ if(!response.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Get a list of the songs saved in the current Spotify user’s “Your Music” library.
|
> Get a list of the songs saved in the current Spotify user’s “Your Music” library.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -63,7 +63,7 @@ savedTracks.Items.ForEach(track => Console.WriteLine(track.Track.Name));
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Remove one or more tracks from the current user’s “Your Music” library.
|
> Remove one or more tracks from the current user’s “Your Music” library.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -83,7 +83,7 @@ if(!response.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Check if one or more tracks is already saved in the current Spotify user’s “Your Music” library.
|
> Check if one or more tracks is already saved in the current Spotify user’s “Your Music” library.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -103,7 +103,7 @@ if(tracksSaved.List[0])
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Save one or more albums to the current user’s “Your Music” library.
|
> Save one or more albums to the current user’s “Your Music” library.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -123,7 +123,7 @@ if(!response.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Save one album to the current user’s “Your Music” library.
|
> Save one album to the current user’s “Your Music” library.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -143,7 +143,7 @@ if(!response.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Get a list of the albums saved in the current Spotify user’s “Your Music” library.
|
> Get a list of the albums saved in the current Spotify user’s “Your Music” library.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -164,7 +164,7 @@ savedAlbums.Items.ForEach(album => Console.WriteLine(album.Album.Name));
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Remove one or more albums from the current user’s “Your Music” library.
|
> Remove one or more albums from the current user’s “Your Music” library.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -184,7 +184,7 @@ if(!response.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Check if one or more albums is already saved in the current Spotify user’s “Your Music” library.
|
> Check if one or more albums is already saved in the current Spotify user’s “Your Music” library.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
## GetDevices
|
## GetDevices
|
||||||
> Get information about a user’s available devices.
|
> Get information about a user’s available devices.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -18,7 +18,7 @@ devices.Devices.ForEach(device => Console.WriteLine(device.Name));
|
|||||||
## GetPlayback
|
## GetPlayback
|
||||||
> Get information about the user’s current playback state, including track, track progress, and active device.
|
> Get information about the user’s current playback state, including track, track progress, and active device.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -37,7 +37,7 @@ if(contex.Item != null)
|
|||||||
## GetPlayingTrack
|
## GetPlayingTrack
|
||||||
> Get the object currently being played on the user’s Spotify account.
|
> Get the object currently being played on the user’s Spotify account.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -58,7 +58,7 @@ if(contex.Item != null)
|
|||||||
## TransferPlayback
|
## TransferPlayback
|
||||||
> Transfer playback to a new device and determine if it should start playing.
|
> Transfer playback to a new device and determine if it should start playing.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -76,7 +76,7 @@ ErrorResponse error = _spotify.TransferPlayback("XXXX-XXXX-XXXX-XXXX");
|
|||||||
## ResumePlayback
|
## ResumePlayback
|
||||||
> Start a new context or resume current playback on the user’s active device.
|
> Start a new context or resume current playback on the user’s active device.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -96,7 +96,7 @@ ErrorResponse error = _spotify.ResumePlayback(uris: new List<string> { "spotify:
|
|||||||
## PausePlayback
|
## PausePlayback
|
||||||
> Pause playback on the user’s account.
|
> Pause playback on the user’s account.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -113,7 +113,7 @@ ErrorResponse error = _spotify.PausePlayback();
|
|||||||
## SkipPlaybackToNext
|
## SkipPlaybackToNext
|
||||||
> Skips to next track in the user’s queue.
|
> Skips to next track in the user’s queue.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -132,7 +132,7 @@ ErrorResponse error = _spotify.SkipPlaybackToNext();
|
|||||||
Note that this will ALWAYS skip to the previous track, regardless of the current track’s progress.
|
Note that this will ALWAYS skip to the previous track, regardless of the current track’s progress.
|
||||||
Returning to the start of the current track should be performed using the https://api.spotify.com/v1/me/player/seek endpoint.
|
Returning to the start of the current track should be performed using the https://api.spotify.com/v1/me/player/seek endpoint.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -149,7 +149,7 @@ ErrorResponse error = _spotify.SkipPlaybackToPrevious();
|
|||||||
## SeekPlayback
|
## SeekPlayback
|
||||||
> Seeks to the given position in the user’s currently playing track.
|
> Seeks to the given position in the user’s currently playing track.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -167,7 +167,7 @@ ErrorResponse error = _spotify.SeekPlayback(50);
|
|||||||
## SetRepeatMode
|
## SetRepeatMode
|
||||||
> Set the repeat mode for the user’s playback. Options are repeat-track, repeat-context, and off.
|
> Set the repeat mode for the user’s playback. Options are repeat-track, repeat-context, and off.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -185,7 +185,7 @@ ErrorResponse error = _spotify.SetRepeatMode(RepeatState.Track);
|
|||||||
## SetVolume
|
## SetVolume
|
||||||
> Set the volume for the user’s current playback device.
|
> Set the volume for the user’s current playback device.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -203,7 +203,7 @@ ErrorResponse error = _spotify.SetVolume(50);
|
|||||||
## SetShuffle
|
## SetShuffle
|
||||||
> Toggle shuffle on or off for user’s playback.
|
> Toggle shuffle on or off for user’s playback.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Get a list of the playlists owned or followed by a Spotify user.
|
> Get a list of the playlists owned or followed by a Spotify user.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -23,7 +23,7 @@ userPlaylists.Items.ForEach(playlist => playlist.Owner.DisplayName) //Who is the
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Get a playlist owned by a Spotify user.
|
> Get a playlist owned by a Spotify user.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -45,7 +45,7 @@ playlist.Tracks.Items.ForEach(track => Console.WriteLine(track.Track.Name));
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Get full details of the tracks of a playlist owned by a Spotify user.
|
> Get full details of the tracks of a playlist owned by a Spotify user.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -69,7 +69,7 @@ playlist.Items.ForEach(track => Console.WriteLine(track.Track.Name));
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Create a playlist for a Spotify user. (The playlist will be empty until you add tracks.)
|
> Create a playlist for a Spotify user. (The playlist will be empty until you add tracks.)
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -91,7 +91,7 @@ if(!playlist.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Change a playlist’s name and public/private state. (The user must, of course, own the playlist.)
|
> Change a playlist’s name and public/private state. (The user must, of course, own the playlist.)
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -114,7 +114,7 @@ if(!response.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Replace all the tracks in a playlist, overwriting its existing tracks. This powerful request can be useful for replacing tracks, re-ordering existing tracks, or clearing the playlist.
|
> Replace all the tracks in a playlist, overwriting its existing tracks. This powerful request can be useful for replacing tracks, re-ordering existing tracks, or clearing the playlist.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -136,7 +136,7 @@ if(!response.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Remove one or more tracks from a user’s playlist.
|
> Remove one or more tracks from a user’s playlist.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -167,7 +167,7 @@ ErrorResponse playlist = _spotify.RemovePlaylistTracks("1122095781", "1TtEejT1y4
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Remove one or more tracks from a user’s playlist.
|
> Remove one or more tracks from a user’s playlist.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -191,7 +191,7 @@ ErrorResponse response = _spotify.RemovePlaylistTrack("1122095781", "1TtEejT1y4D
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Add one or more tracks to a user’s playlist.
|
> Add one or more tracks to a user’s playlist.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -214,7 +214,7 @@ if(!response.HasError())
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Add one or more tracks to a user’s playlist.
|
> Add one or more tracks to a user’s playlist.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -238,7 +238,7 @@ if(!response.HasError())
|
|||||||
> Reorder a track or a group of tracks in a playlist.
|
> Reorder a track or a group of tracks in a playlist.
|
||||||
> More Info: [Reorder-Playlist](https://developer.spotify.com/web-api/reorder-playlists-tracks/)
|
> More Info: [Reorder-Playlist](https://developer.spotify.com/web-api/reorder-playlists-tracks/)
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<span class="label label-warning">AUTH REQUIRED</span>
|
<span class="label label-warning">AUTH REQUIRED</span>
|
||||||
> Get detailed profile information about the current user (including the current user’s username).
|
> Get detailed profile information about the current user (including the current user’s username).
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -21,7 +21,7 @@ Console.WriteLine(user.DisplayName);
|
|||||||
|
|
||||||
> Get public profile information about a Spotify user.
|
> Get public profile information about a Spotify user.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
> Get Spotify catalog information about artists, albums, tracks or playlists that match a keyword string.
|
> Get Spotify catalog information about artists, albums, tracks or playlists that match a keyword string.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
> Get Spotify catalog information for multiple tracks based on their Spotify IDs.
|
> Get Spotify catalog information for multiple tracks based on their Spotify IDs.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -22,7 +22,7 @@ severalTracks.Tracks.ForEach(track => Console.WriteLine(track.Name));
|
|||||||
|
|
||||||
> Get Spotify catalog information for a single track identified by its unique Spotify ID.
|
> Get Spotify catalog information for a single track identified by its unique Spotify ID.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
@ -42,7 +42,7 @@ Console.WriteLine(track.Name);
|
|||||||
|
|
||||||
> Get a detailed audio analysis for a single track identified by its unique Spotify ID.
|
> Get a detailed audio analysis for a single track identified by its unique Spotify ID.
|
||||||
|
|
||||||
**Paramters**
|
**Parameters**
|
||||||
|
|
||||||
|Name|Description|Example|
|
|Name|Description|Example|
|
||||||
|--------------|-------------------------|-------------------------|
|
|--------------|-------------------------|-------------------------|
|
||||||
|
@ -2,17 +2,17 @@
|
|||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
This Library, written in C#/.NET, combines two independent SpotifyAPIs into one.
|
This project, written in C#/.NET, provides 2 libraries for an easier usage of the Spotify Web API
|
||||||
|
|
||||||
**Spotify's Web API** ([link](https://developer.spotify.com/web-api/))
|
**Spotify's Web API** ([link](https://developer.spotify.com/web-api/))
|
||||||
> Based on simple REST principles, our Web API endpoints return metadata in JSON format about artists, albums, and tracks directly from the Spotify catalogue.
|
> Based on simple REST principles, our Web API endpoints return metadata in JSON format about artists, albums, and tracks directly from the Spotify catalogue.
|
||||||
> The API also provides access to user-related data such as playlists and music saved in a “Your Music” library, subject to user’s authorization.
|
> The API also provides access to user-related data such as playlists and music saved in a “Your Music” library, subject to user’s authorization.
|
||||||
|
|
||||||
**Spotify's *unofficial* Local API**
|
**SpotifyAPI.Web**
|
||||||
> Do you ever wanted to control your local Spotify Client with some sort of API? Now you can! This API gives you full control over your spotify client.
|
> A wrapper around Spotify's Web API, providing sync and async methods to query all possible endpoints. Results are returned as typed class instances, allowing property-based access.
|
||||||
> You can get infos about the currently playing song, get its Album-Art, skip/pause and much more. It also features multiple Event-Interfaces.
|
|
||||||
|
|
||||||
Both combined can be used for any kind of application.
|
**SpotifyAPI.Web.Auth**
|
||||||
|
> A library providing C# implementations of the 3 supported Authentication modes, including `ImplicitGrantAuth`, `AuthorizationCodeAuth` and `CredentialsAuth`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -20,12 +20,11 @@ Both combined can be used for any kind of application.
|
|||||||
|
|
||||||
* Via NuGet Package:
|
* Via NuGet Package:
|
||||||
```cs
|
```cs
|
||||||
Install-Package SpotifyAPI-NET
|
Install-Package SpotifyAPI.Web
|
||||||
//or
|
Install-Package SpotifyAPI.Web.Auth
|
||||||
Install-Package SpotifyAPI-NET -pre
|
|
||||||
```
|
```
|
||||||
* Download the latest binaries on the [GitHub Release Page](https://github.com/JohnnyCrazy/SpotifyAPI-NET/releases) and add it to your Project
|
* Download the latest binaries on the [GitHub Release Page](https://github.com/JohnnyCrazy/SpotifyAPI-NET/releases) and add it to your Project
|
||||||
* Clone the Repo and build the project on your local machine.
|
* Clone the Repo and build the project yourself.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -37,8 +36,8 @@ Install-Package SpotifyAPI-NET -pre
|
|||||||
|
|
||||||
### [Toastify](https://github.com/aleab/toastify) by [@aleab](https://github.com/aleab)
|
### [Toastify](https://github.com/aleab/toastify) by [@aleab](https://github.com/aleab)
|
||||||
|
|
||||||
> Toastify adds global hotkeys and toast notifications to Spotify
|
> Toastify adds global hotkeys and toast notifications to Spotify
|
||||||
>
|
>
|
||||||
> *Forked from [nachmore/toastify](https://github.com/nachmore/toastify)*
|
> *Forked from [nachmore/toastify](https://github.com/nachmore/toastify)*
|
||||||
|
|
||||||
### [Spotify Oculus](https://github.com/CaptainMorgs/spotify-oculus-release) by [@CaptainMorgs](https://github.com/CaptainMorgs)
|
### [Spotify Oculus](https://github.com/CaptainMorgs/spotify-oculus-release) by [@CaptainMorgs](https://github.com/CaptainMorgs)
|
||||||
|
@ -2,10 +2,9 @@ site_name: 'SpotifyAPI-NET'
|
|||||||
theme_dir: 'mytheme'
|
theme_dir: 'mytheme'
|
||||||
pages:
|
pages:
|
||||||
- 'Home': 'index.md'
|
- 'Home': 'index.md'
|
||||||
- 'SpotifyWebAPI':
|
- 'SpotifyAPI.Web':
|
||||||
- 'Getting started': 'SpotifyWebAPI/gettingstarted.md'
|
- 'Getting started': 'SpotifyWebAPI/gettingstarted.md'
|
||||||
- 'Examples': 'SpotifyWebAPI/examples.md'
|
- 'Examples': 'SpotifyWebAPI/examples.md'
|
||||||
- 'Authentication': 'SpotifyWebAPI/auth.md'
|
|
||||||
- 'Proxy': 'SpotifyWebAPI/proxy.md'
|
- 'Proxy': 'SpotifyWebAPI/proxy.md'
|
||||||
- '- Albums': 'SpotifyWebAPI/albums.md'
|
- '- Albums': 'SpotifyWebAPI/albums.md'
|
||||||
- '- Artists': 'SpotifyWebAPI/artists.md'
|
- '- Artists': 'SpotifyWebAPI/artists.md'
|
||||||
@ -19,10 +18,10 @@ pages:
|
|||||||
- '- Search': 'SpotifyWebAPI/search.md'
|
- '- Search': 'SpotifyWebAPI/search.md'
|
||||||
- '- Tracks': 'SpotifyWebAPI/tracks.md'
|
- '- Tracks': 'SpotifyWebAPI/tracks.md'
|
||||||
- '- Util': 'SpotifyWebAPI/util.md'
|
- '- Util': 'SpotifyWebAPI/util.md'
|
||||||
- 'SpotifyLocalAPI': 'SpotifyLocalAPI/index.md'
|
- 'SpotifyAPI.Web.Auth': 'SpotifyWebAPI/auth.md'
|
||||||
repo_url: 'https://github.com/JohnnyCrazy/SpotifyAPI-NET'
|
repo_url: 'https://github.com/JohnnyCrazy/SpotifyAPI-NET'
|
||||||
site_author: 'JohnnyCrazy'
|
site_author: 'JohnnyCrazy'
|
||||||
site_description: 'API Docs for SpotifyAPI-NET'
|
site_description: 'API Docs for SpotifyAPI.Web and SpotifyAPI.Web.Auth'
|
||||||
extra_javascript:
|
extra_javascript:
|
||||||
- 'highlight.js'
|
- 'highlight.js'
|
||||||
markdown_extensions:
|
markdown_extensions:
|
||||||
|
@ -10,10 +10,6 @@ using SpotifyAPI.Web.Models;
|
|||||||
using Unosquare.Labs.EmbedIO;
|
using Unosquare.Labs.EmbedIO;
|
||||||
using Unosquare.Labs.EmbedIO.Constants;
|
using Unosquare.Labs.EmbedIO.Constants;
|
||||||
using Unosquare.Labs.EmbedIO.Modules;
|
using Unosquare.Labs.EmbedIO.Modules;
|
||||||
using Unosquare.Swan;
|
|
||||||
#if NET46
|
|
||||||
using HttpListenerContext = Unosquare.Net.HttpListenerContext;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Auth
|
namespace SpotifyAPI.Web.Auth
|
||||||
{
|
{
|
||||||
@ -43,9 +39,9 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
return ShouldRegisterNewApp() ? $"{RedirectUri}/start.html#{State}" : base.GetUri();
|
return ShouldRegisterNewApp() ? $"{RedirectUri}/start.html#{State}" : base.GetUri();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override WebServer AdaptWebServer(WebServer webServer)
|
protected override void AdaptWebServer(WebServer webServer)
|
||||||
{
|
{
|
||||||
return webServer.WithWebApiController<AuthorizationCodeAuthController>();
|
webServer.Module<WebApiModule>().RegisterController<AuthorizationCodeAuthController>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetAuthHeader() => $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes(ClientId + ":" + SecretId))}";
|
private string GetAuthHeader() => $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes(ClientId + ":" + SecretId))}";
|
||||||
@ -97,29 +93,29 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
internal class AuthorizationCodeAuthController : WebApiController
|
internal class AuthorizationCodeAuthController : WebApiController
|
||||||
{
|
{
|
||||||
[WebApiHandler(HttpVerbs.Get, "/")]
|
[WebApiHandler(HttpVerbs.Get, "/")]
|
||||||
public Task<bool> GetEmpty(WebServer server, HttpListenerContext context)
|
public Task<bool> GetEmpty()
|
||||||
{
|
{
|
||||||
string state = context.Request.QueryString["state"];
|
string state = Request.QueryString["state"];
|
||||||
AuthorizationCodeAuth.Instances.TryGetValue(state, out SpotifyAuthServer<AuthorizationCode> auth);
|
AuthorizationCodeAuth.Instances.TryGetValue(state, out SpotifyAuthServer<AuthorizationCode> auth);
|
||||||
|
|
||||||
string code = null;
|
string code = null;
|
||||||
string error = context.Request.QueryString["error"];
|
string error = Request.QueryString["error"];
|
||||||
if (error == null)
|
if (error == null)
|
||||||
code = context.Request.QueryString["code"];
|
code = Request.QueryString["code"];
|
||||||
|
|
||||||
Task.Factory.StartNew(() => auth?.TriggerAuth(new AuthorizationCode
|
Task.Factory.StartNew(() => auth?.TriggerAuth(new AuthorizationCode
|
||||||
{
|
{
|
||||||
Code = code,
|
Code = code,
|
||||||
Error = error
|
Error = error
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return context.StringResponseAsync("OK - This window can be closed now");
|
return this.StringResponseAsync("OK - This window can be closed now");
|
||||||
}
|
}
|
||||||
|
|
||||||
[WebApiHandler(HttpVerbs.Post, "/")]
|
[WebApiHandler(HttpVerbs.Post, "/")]
|
||||||
public bool PostValues(WebServer server, HttpListenerContext context)
|
public bool PostValues()
|
||||||
{
|
{
|
||||||
Dictionary<string, object> formParams = context.RequestFormDataDictionary();
|
Dictionary<string, object> formParams = this.RequestFormDataDictionary();
|
||||||
|
|
||||||
string state = (string) formParams["state"];
|
string state = (string) formParams["state"];
|
||||||
AuthorizationCodeAuth.Instances.TryGetValue(state, out SpotifyAuthServer<AuthorizationCode> authServer);
|
AuthorizationCodeAuth.Instances.TryGetValue(state, out SpotifyAuthServer<AuthorizationCode> authServer);
|
||||||
@ -129,7 +125,11 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
auth.SecretId = (string) formParams["secretId"];
|
auth.SecretId = (string) formParams["secretId"];
|
||||||
|
|
||||||
string uri = auth.GetUri();
|
string uri = auth.GetUri();
|
||||||
return context.Redirect(uri, false);
|
return this.Redirect(uri, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AuthorizationCodeAuthController(IHttpContext context) : base(context)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,32 +24,30 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
ClientId = clientId;
|
ClientId = clientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override WebServer AdaptWebServer(WebServer webServer)
|
protected override void AdaptWebServer(WebServer webServer)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Hello");
|
|
||||||
webServer.Module<WebApiModule>().RegisterController<ImplictGrantAuthController>();
|
webServer.Module<WebApiModule>().RegisterController<ImplictGrantAuthController>();
|
||||||
return webServer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ImplictGrantAuthController : WebApiController
|
public class ImplictGrantAuthController : WebApiController
|
||||||
{
|
{
|
||||||
[WebApiHandler(HttpVerbs.Get, "/auth")]
|
[WebApiHandler(HttpVerbs.Get, "/auth")]
|
||||||
public Task<bool> GetAuth(WebServer server, HttpListenerContext context)
|
public Task<bool> GetAuth()
|
||||||
{
|
{
|
||||||
string state = context.Request.QueryString["state"];
|
string state = Request.QueryString["state"];
|
||||||
SpotifyAuthServer<Token> auth = ImplictGrantAuth.GetByState(state);
|
SpotifyAuthServer<Token> auth = ImplictGrantAuth.GetByState(state);
|
||||||
if (auth == null)
|
if (auth == null)
|
||||||
return context.StringResponseAsync(
|
return this.StringResponseAsync(
|
||||||
$"Failed - Unable to find auth request with state \"{state}\" - Please retry");
|
$"Failed - Unable to find auth request with state \"{state}\" - Please retry");
|
||||||
|
|
||||||
Token token;
|
Token token;
|
||||||
string error = context.Request.QueryString["error"];
|
string error = Request.QueryString["error"];
|
||||||
if (error == null)
|
if (error == null)
|
||||||
{
|
{
|
||||||
string accessToken = context.Request.QueryString["access_token"];
|
string accessToken = Request.QueryString["access_token"];
|
||||||
string tokenType = context.Request.QueryString["token_type"];
|
string tokenType = Request.QueryString["token_type"];
|
||||||
string expiresIn = context.Request.QueryString["expires_in"];
|
string expiresIn = Request.QueryString["expires_in"];
|
||||||
token = new Token
|
token = new Token
|
||||||
{
|
{
|
||||||
AccessToken = accessToken,
|
AccessToken = accessToken,
|
||||||
@ -66,7 +64,11 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
}
|
}
|
||||||
|
|
||||||
Task.Factory.StartNew(() => auth.TriggerAuth(token));
|
Task.Factory.StartNew(() => auth.TriggerAuth(token));
|
||||||
return context.StringResponseAsync("OK - This window can be closed now");
|
return this.StringResponseAsync("OK - This window can be closed now");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImplictGrantAuthController(IHttpContext context) : base(context)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
|
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
@ -15,7 +15,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="EmbedIO" Version="1.16.0" />
|
<PackageReference Include="EmbedIO" Version="2.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using SpotifyAPI.Web.Enums;
|
using SpotifyAPI.Web.Enums;
|
||||||
@ -44,10 +45,10 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
Instances.Add(State, this);
|
Instances.Add(State, this);
|
||||||
_serverSource = new CancellationTokenSource();
|
_serverSource = new CancellationTokenSource();
|
||||||
|
|
||||||
_server = WebServer.Create(ServerUri, RoutingStrategy.Regex);
|
_server = WebServer.Create(ServerUri);
|
||||||
_server.RegisterModule(new WebApiModule());
|
_server.RegisterModule(new WebApiModule());
|
||||||
AdaptWebServer(_server);
|
AdaptWebServer(_server);
|
||||||
_server.RegisterModule(new ResourceFilesModule(typeof(T).Assembly, $"SpotifyAPI.Web.Auth.Resources.{_folder}"));
|
_server.RegisterModule(new ResourceFilesModule(Assembly.GetExecutingAssembly(), $"SpotifyAPI.Web.Auth.Resources.{_folder}"));
|
||||||
#pragma warning disable 4014
|
#pragma warning disable 4014
|
||||||
_server.RunAsync(_serverSource.Token);
|
_server.RunAsync(_serverSource.Token);
|
||||||
#pragma warning restore 4014
|
#pragma warning restore 4014
|
||||||
@ -88,6 +89,6 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
return Instances.TryGetValue(state, out SpotifyAuthServer<T> auth) ? auth : null;
|
return Instances.TryGetValue(state, out SpotifyAuthServer<T> auth) ? auth : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract WebServer AdaptWebServer(WebServer webServer);
|
protected abstract void AdaptWebServer(WebServer webServer);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using SpotifyAPI.Web.Auth;
|
using SpotifyAPI.Web.Auth;
|
||||||
using SpotifyAPI.Web.Enums;
|
using SpotifyAPI.Web.Enums;
|
||||||
using SpotifyAPI.Web.Models;
|
using SpotifyAPI.Web.Models;
|
||||||
@ -25,15 +24,11 @@ namespace SpotifyAPI.Web.Example
|
|||||||
Console.WriteLine("This example uses AuthorizationCodeAuth.");
|
Console.WriteLine("This example uses AuthorizationCodeAuth.");
|
||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
"Tip: If you want to supply your ClientID and SecretId beforehand, use env variables (SPOTIFY_CLIENT_ID and SPOTIFY_SECRET_ID)");
|
"Tip: If you want to supply your ClientID and SecretId beforehand, use env variables (SPOTIFY_CLIENT_ID and SPOTIFY_SECRET_ID)");
|
||||||
|
|
||||||
|
CredentialsAuth auth = new CredentialsAuth(_clientId, _secretId);
|
||||||
AuthorizationCodeAuth auth =
|
Token token = await auth.GetToken();
|
||||||
new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",
|
SpotifyWebAPI api = new SpotifyWebAPI() { TokenType = token.TokenType, AccessToken = token.AccessToken};
|
||||||
Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative);
|
|
||||||
auth.AuthReceived += AuthOnAuthReceived;
|
|
||||||
auth.Start();
|
|
||||||
auth.OpenBrowser();
|
|
||||||
|
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
auth.Stop(0);
|
auth.Stop(0);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||||
@ -7,11 +7,11 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0-preview-20181205-02" />
|
||||||
<PackageReference Include="Moq" Version="4.9.0" />
|
<PackageReference Include="Moq" Version="4.10.1" />
|
||||||
<PackageReference Include="NUnit" Version="3.10.1" />
|
<PackageReference Include="NUnit" Version="3.11.0" />
|
||||||
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
|
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
|
||||||
<PackageReference Include="NUnit.Console" Version="3.8.0" />
|
<PackageReference Include="NUnit.Console" Version="3.9.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;net46</TargetFrameworks>
|
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
@ -15,7 +15,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
|
||||||
|
Loading…
Reference in New Issue
Block a user