Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Tuesday, 06 January 2015
( c# | JSON | Spotify )

Goal: Get API calls working to Spotify using a console app

http://www.royjacobs.org/blog/2012/11/13/importing-m3u-playlists-into-spotify/ – c# importer (no auth)

image
Using a deprecated call

image
Interesting I’m getting 224 results back!

image
Can type in the Href and test have got the correct song back.

Searching

http://ws.spotify.com/search/1/track?q=Metallica+One
This old Metadata API, which is now deprecated (but still working).

image
Old API returning XML.

https://api.spotify.com/v1/search?q=metallica&type=artist
The Web API

image
JSON Formatter extension for Chrome

https://developer.spotify.com/web-api/console/
Interactive Console for exploring the API

  • Album
  • Artist
  • Track
  • Playlist

Exploring the json and viewing the image URL’s that are returned

image

An image of the band
https://i.scdn.co/image/15d9ccb37a96d49f69f44f999fb1e9e46f9b3ccd

Am using Newtonsoft’s JsonConvert.DeserializeObject<T> to get into a POCO:

image
Used the API to get a simple search going on the web.

Exploring the json returned results, finding that some artists return 3,4 or 0 images.  So put some simple view logic in to force display of 200 width.  And put in a sample default band (muse) on page load of http://www.davesjokes.co.uk/Home/SpotifyArtistSearch

image

Offset and Limit

https://developer.spotify.com/web-api/search-item/
https://api.spotify.com/v1/search?query=muse&offset=20&limit=20&type=artist

Limit default is 20, max is 50.

Timing

var stopWatch = new Stopwatch(); stopWatch.Start(); string json = CallSpotifyAPI(artistName); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; string elapsedTime = String.Format("{0:0}",ts.TotalMilliseconds); ViewBag.APITime = elapsedTime;
TotalMilliseconds is handy.  Format makes sure no decimal points in the ms.

image
Timing code.  Next and previous buttons.  All GET requests now – form submits via querystring.  Title is different if no search.

| | #