Skip to content

Commit 6f12638

Browse files
author
Jonas Dellinger
committed
Added docs to main branch
1 parent 0f993ce commit 6f12638

36 files changed

Lines changed: 3518 additions & 0 deletions

‎SpotifyAPI.Docs/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
site/

‎SpotifyAPI.Docs/.travis.yml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: python
2+
python:
3+
- "3.4"
4+
# command to install dependencies
5+
install:
6+
- "pip install mkdocs"
7+
env:
8+
global:
9+
- secure: "TrPdzgDDelezvEch5VmGkn0gu7E/4imfdae85qr7pPvk4jwdYtBI918+fgMkT8oowEfrd14M39dttpVrp8Fjns+QsWoy742F/N8bc+HiEDzKNnc2KJgA5AF5KysdDeQthDEn8egeOlzLjMY7L/JPj67Ene8fik1IdkpFpMwNnf8="
10+
# command to run tests
11+
before_script: "mkdocs build --clean"
12+
script:
13+
- "chmod ugo+x ./push-ghpages.sh"
14+
- "./push-ghpages.sh"
15+
sudo: false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# WIP
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
##GetAlbumTracks
2+
> Get Spotify catalog information about an album's tracks. Optional parameters can be used to limit the number of tracks returned.
3+
4+
**Paramters**
5+
6+
|Name|Description|Example|
7+
|--------------|-------------------------|-------------------------|
8+
|id| The Spotify ID for the album. | `"5O7V8l4SeXTymVp3IesT9C"`
9+
|[limit]| The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. | `20`
10+
|[offset]| The index of the first track to return. Default: 0 (the first object). | `0`
11+
|[market]| An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. | `"DE"`
12+
13+
Returns a [SimpleTrack](https://developer.spotify.com/web-api/object-model/#track-object-simplified) wrapped inside a [Paging-object](https://developer.spotify.com/web-api/object-model/#paging-object)
14+
15+
**Usage**
16+
17+
```cs
18+
Paging<SimpleTrack> tracks = _spotify.GetAlbumTracks("5O7V8l4SeXTymVp3IesT9C");
19+
tracks.Items.ForEach(item => Console.WriteLine(item.Name)); //Display all fetched Track-Names (max 20)
20+
Console.WriteLine(tracks.Total.ToString()) //Display total album track count
21+
```
22+
23+
---
24+
##GetAlbum
25+
> Get Spotify catalog information for a single album.
26+
27+
**Paramters**
28+
29+
|Name|Description|Example|
30+
|--------------|-------------------------|-------------------------|
31+
|id| The Spotify ID for the album. | `5O7V8l4SeXTymVp3IesT9C`
32+
|[market]| An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. | `"DE"`
33+
34+
Returns a [FullAlbum](https://developer.spotify.com/web-api/object-model/#album-object-full)
35+
36+
**Usage**
37+
```cs
38+
FullAlbum album = _spotify.GetAlbum("5O7V8l4SeXTymVp3IesT9C");
39+
Console.WriteLine(album.Name + "| Popularity: " + album.Popularity); //Display name and Popularity
40+
```
41+
42+
---
43+
##GetSeveralAlbums
44+
> Get Spotify catalog information for multiple albums identified by their Spotify IDs.
45+
46+
**Paramters**
47+
48+
|Name|Description|Example|
49+
|--------------|-------------------------|-------------------------|
50+
|ids| A list of the Spotify IDs for the albums. Maximum: 20 IDs. | `new List<String>() { "5O7V8l4SeXTymVp3IesT9C" }`
51+
|[market]| An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. | `"DE"`
52+
53+
Returns a **SeveralAlbums** which Property "Albums" contains a list of [FullAlbum](https://developer.spotify.com/web-api/object-model/#album-object-full)
54+
55+
**Usage**
56+
```cs
57+
SeveralAlbums albums = _spotify.GetSeveralAlbums(new List<String>() { "5O7V8l4SeXTymVp3IesT9C" });
58+
Console.WriteLine(albums.Albums[0].Name);
59+
```
60+
61+
---
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
##GetArtist
2+
3+
> Get Spotify catalog information for a single artist identified by their unique Spotify ID.
4+
5+
**Paramters**
6+
7+
|Name|Description|Example|
8+
|--------------|-------------------------|-------------------------|
9+
|id| The Spotify ID for the artist. | `"1KpCi9BOfviCVhmpI4G2sY"`
10+
11+
Returns a [FullArtist](https://developer.spotify.com/web-api/object-model/#artist-object-full)
12+
13+
**Usage**
14+
```cs
15+
FullArtist artist = _spotify.GetArtist("1KpCi9BOfviCVhmpI4G2sY");
16+
Console.WriteLine()
17+
```
18+
19+
---
20+
##GetRelatedArtists
21+
> Get Spotify catalog information about artists similar to a given artist. Similarity is based on analysis of the Spotify community's listening history.
22+
23+
**Paramters**
24+
25+
|Name|Description|Example|
26+
|--------------|-------------------------|-------------------------|
27+
|id| The Spotify ID for the artist. | `"1KpCi9BOfviCVhmpI4G2sY"`
28+
29+
Returns a **SeveralArtists** object which contains the property `List<FullArtist> Artists` ([FullArtist](https://developer.spotify.com/web-api/object-model/#artist-object-full))
30+
31+
**Usage**
32+
```cs
33+
SeveralArtists artists = _spotify.GetRelatedArtists("1KpCi9BOfviCVhmpI4G2sY");
34+
Console.WriteLine(artists.Artists[0].Name);
35+
```
36+
37+
---
38+
##GetArtistsTopTracks
39+
> Get Spotify catalog information about an artist's top tracks by country.
40+
41+
**Paramters**
42+
43+
|Name|Description|Example|
44+
|--------------|-------------------------|-------------------------|
45+
|id| The Spotify ID for the artist. | `"1KpCi9BOfviCVhmpI4G2sY"`
46+
|country| The country: an ISO 3166-1 alpha-2 country code. | `"DE"`
47+
48+
Returns a **SeveralTracks** object which contains the property `List<FullTrack> Tracks` ([FullTrack](https://developer.spotify.com/web-api/object-model/#track-object-full))
49+
50+
**Usage**
51+
```cs
52+
SeveralTracks tracks = _spotify.GetArtistsTopTracks("1KpCi9BOfviCVhmpI4G2sY", "DE");
53+
Console.WriteLine(tracks.Tracks.Count); //How many tracks did we get?
54+
```
55+
56+
---
57+
##GetArtistsAlbums
58+
> Get Spotify catalog information about an artist's albums. Optional parameters can be specified in the query string to filter and sort the response.
59+
60+
**Paramters**
61+
62+
|Name|Description|Example|
63+
|--------------|-------------------------|-------------------------|
64+
|id| The Spotify ID for the artist. | `"1KpCi9BOfviCVhmpI4G2sY"`
65+
|[type]| A list of keywords that will be used to filter the response. If not supplied, all album types will be returned | `AlbumType.All`
66+
|[limit]| The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. | `20`
67+
|[offset]| The index of the first album to return. Default: 0 | `0`
68+
|[market]| An ISO 3166-1 alpha-2 country code. Supply this parameter to limit the response to one particular geographical market | `"DE"`
69+
70+
Returns a [SimpleAlbum](https://developer.spotify.com/web-api/object-model/#album-object-simplified) wrapped inside a [Paging-object](https://developer.spotify.com/web-api/object-model/#paging-object)
71+
72+
**Usage**
73+
```cs
74+
Paging<SimpleAlbum> albums = _spotify.GetArtistsAlbums("1KpCi9BOfviCVhmpI4G2sY", AlbumType.All);
75+
albums.Items.ForEach(album => Console.WriteLine(album.Name));
76+
```
77+
78+
---
79+
##GetSeveralArtists
80+
> Get Spotify catalog information for several artists based on their Spotify IDs.
81+
82+
**Paramters**
83+
84+
|Name|Description|Example|
85+
|--------------|-------------------------|-------------------------|
86+
|ids| A list of the Spotify IDs for the artists. Maximum: 50 IDs. | `new List<String>() { "1KpCi9BOfviCVhmpI4G2sY" } `
87+
88+
Returns a **SeveralArtists** object which contains the property `List<FullArtist> Artists` ([FullArtist](https://developer.spotify.com/web-api/object-model/#artist-object-full))
89+
90+
**Usage**
91+
```cs
92+
SeveralArtists artists = _spotify.GetSeveralArtists(new List<String>() {"1KpCi9BOfviCVhmpI4G2sY"});
93+
artists.Artists.ForEach(artist => Console.WriteLine(artist.Name));
94+
```
95+
96+
---
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#Auth-Methods
2+
3+
Before you can use the Web API full functional, you need the user to authenticate your Application.
4+
If you want to know more, you can read to the whole auth-process [here](https://developer.spotify.com/web-api/authorization-guide/).
5+
6+
Before you start, you need to create a Application at Spotify: [Your Applications](https://developer.spotify.com/my-applications/#!/applications)
7+
8+
***
9+
10+
After you created your Application, you will have following important values:
11+
>**Client_Id** This is your client_id, you don't have to hide it
12+
>**Client_Secret** Never use this in one of your client-side apps!! Keep it secret!
13+
>**Redirect URIs** Add "http://localhost", if you want full support for this API
14+
15+
Now you can start with the User-authentication, Spotify provides 3 ways:
16+
17+
* [ImplicitGrantAuth](/SpotifyWebAPI/auth#implicitgrantauth) (**Recommended**, no server-side code needed)
18+
19+
* [AutorizationCodeAuth](/SpotifyWebAPI/auth#autorizationcodeauth) (Not Recommended, Server-side code needed, else it's unsecure)
20+
21+
* [ClientCredentialsAuth](/SpotifyWebAPI/auth#clientcredentialsauth) (Not Recommended, Server-side code needed, else it's unsecure)
22+
23+
**Note:** I would recommend a little PHP Script, which will exchange the Keys using AutorizationCodeAuth.
24+
When using ImplicitGrantAuth, another user could abuse the "localhost" RedirectUri by creating a "fake"-app which uses your ClientId.
25+
26+
Overview:
27+
![Overview](http://i.imgur.com/uf3ahTl.png)
28+
29+
After implementing one of the provided auth-methods, you can start doing requests with the token you get from one of the auth-methods
30+
31+
##ImplicitGrantAuth
32+
33+
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.
34+
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.
35+
36+
More info: [here](https://developer.spotify.com/web-api/authorization-guide/#implicit_grant_flow)
37+
38+
For this kind of authentication, there is also a `WebAPIFactory`, it's easier to use and uses an async method:
39+
```
40+
static async void Main(string[] args)
41+
{
42+
WebAPIFactory webApiFactory = new WebAPIFactory(
43+
"http://localhost",
44+
8000,
45+
"XXXXXXXXXXXXXXXX",
46+
Scope.UserReadPrivate,
47+
TimeSpan.FromSeconds(20)
48+
);
49+
50+
try
51+
{
52+
//This will open the user's browser and returns once
53+
//the user is authorized.
54+
_spotify = await webApiFactory.GetWebApi();
55+
}
56+
catch (Exception ex)
57+
{
58+
MessageBox.Show(ex.Message);
59+
}
60+
61+
if (_spotify == null)
62+
return;
63+
}
64+
```
65+
66+
The old way:
67+
```
68+
static ImplicitGrantAuth auth;
69+
static void Main(string[] args)
70+
{
71+
//Create the auth object
72+
auth = new ImplicitGrantAuth()
73+
{
74+
//Your client Id
75+
ClientId = "XXXXXXXXXXXXXXXX",
76+
//Set this to localhost if you want to use the built-in HTTP Server
77+
RedirectUri = "http://localhost",
78+
//How many permissions we need?
79+
Scope = Scope.USER_READ_PRIVATE,
80+
};
81+
//Start the internal http server
82+
auth.StartHttpServer();
83+
//When we got our response
84+
auth.OnResponseReceivedEvent += auth_OnResponseReceivedEvent;
85+
//Start
86+
auth.DoAuth();
87+
}
88+
89+
static void auth_OnResponseReceivedEvent(Token token, string state, string error)
90+
{
91+
//stop the http server
92+
auth.StopHttpServer();
93+
94+
var spotify = new SpotifyWebApiClass()
95+
{
96+
TokenType = token.TokenType,
97+
AccessToken = token.AccessToken
98+
};
99+
//We can now make calls with the token object
100+
}
101+
```
102+
103+
##AutorizationCodeAuth
104+
105+
This way is **not recommended** and requires server-side code to run securely.
106+
With this approach, you first get a code which you need to trade against the access-token.
107+
In this exchange you need to provide your Client-Secret and because of that it's not recommended.
108+
(But you can e.g exchange to codes via a PHP Script)
109+
A good thing about this method: You can always refresh your token, without having the user to auth it again
110+
111+
More info: [here](https://developer.spotify.com/web-api/authorization-guide/#authorization_code_flow)
112+
113+
```
114+
static AutorizationCodeAuth auth;
115+
static void Main(string[] args)
116+
{
117+
//Create the auth object
118+
auth = new AutorizationCodeAuth()
119+
{
120+
//Your client Id
121+
ClientId = "XXXXXXXXXXXXXXX",
122+
//Set this to localhost if you want to use the built-in HTTP Server
123+
RedirectUri = "http://localhost",
124+
//How many permissions we need?
125+
Scope = Scope.USER_READ_PRIVATE,
126+
};
127+
//This will be called, if the user cancled/accept the auth-request
128+
auth.OnResponseReceivedEvent += auth_OnResponseReceivedEvent;
129+
//a local HTTP Server will be started (Needed for the response)
130+
auth.StartHttpServer();
131+
//This will open the spotify auth-page. The user can decline/accept the request
132+
auth.DoAuth();
133+
134+
Thread.Sleep(60000);
135+
auth.StopHttpServer();
136+
Console.WriteLine("Too long, didnt respond, exiting now...");
137+
}
138+
139+
private static void auth_OnResponseReceivedEvent(AutorizationCodeAuthResponse response)
140+
{
141+
//Stop the HTTP Server, done.
142+
auth.StopHttpServer();
143+
144+
//NEVER DO THIS! You would need to provide the ClientSecret.
145+
//You would need to do it e.g via a PHP-Script.
146+
Token token = auth.ExchangeAuthCode(response.Code, "XXXXXXXXXXX");
147+
148+
var spotify = new SpotifyWebApiClass()
149+
{
150+
TokenType = token.TokenType,
151+
AccessToken = token.AccessToken
152+
};
153+
154+
//With the token object, you can now make API calls
155+
}
156+
```
157+
158+
##ClientCredentialsAuth
159+
160+
This way is **not recommended** and requires server-side code to run securely.
161+
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.
162+
If you want to use it securely, you would need to do it all server-side.
163+
**NOTE:** You will only be able to query non-user-related information e.g search for a Track.
164+
165+
More info: [here](https://developer.spotify.com/web-api/authorization-guide/#client_credentials_flow)
166+
167+
```
168+
static ClientCredentialsAuth auth;
169+
static void Main(string[] args)
170+
{
171+
//Create the auth object
172+
auth = new ClientCredentialsAuth()
173+
{
174+
//Your client Id
175+
ClientId = "XXXXXXXXXXXXXXX",
176+
//Your client secret UNSECURE!!
177+
ClientSecret = "XXXXXXXXXXXX",
178+
//How many permissions we need?
179+
Scope = Scope.USER_READ_PRIVATE,
180+
};
181+
//With this token object, we now can make calls
182+
Token token = auth.DoAuth();
183+
var spotify = new SpotifyWebApiClass()
184+
{
185+
TokenType = token.TokenType,
186+
AccessToken = token.AccessToken,
187+
UseAuth = false
188+
};
189+
}
190+
```
191+
192+
#Scopes

0 commit comments

Comments
 (0)