5

I've been playing around with the new Spotify Apps API since yesterday but even though the documentation they have online is pretty good, I can't find anything on to use the API object you receive after calling getSpotifyApi(1). They have some sort of API reference online but no description of how to get these objects, how to access built-in resources such as graphics etc. All in all, I feel like I am missing something. I was able to play around with it by examining the API using the developer inspector and looking at some of the available apps. Is there any way to look at the Javascript code?

mbuchetics
  • 1,370
  • 1
  • 17
  • 34

4 Answers4

16

As others have said, it WAS possible to browse the source and view a sample "API" application, but neither of these are available anymore. For this reason, I have put together a kitchen sink application, which demonstrates how to perform much of the basic functionality. It may come in handy to anyone getting started:

https://github.com/ptrwtts/kitchensink

In the README, there is also a list of helpful resources, but I shall copy some of them here for easy access:

Docs

Spotify Apps Docs: http://developer.spotify.com/en/spotify-apps-api/overview/

Building a Spotify App: http://musicmachinery.com/2011/12/02/building-a-spotify-app/

PasteBin Examples: http://pastebin.com/u/MrSiir

Apps

Tutorial: http://developer.spotify.com/download/spotify-apps-api/tutorial/

Mood Knobs: https://github.com/alexmic/mood-knobs

Spartify: https://github.com/blixt/spartify

SpotifyEchoNestPlaylistDemo: https://gist.github.com/1438262

Peter Watts
  • 720
  • 4
  • 16
7

At the moment the documentation is very sparse. I found it helpful to have a look at Spotify.app's resources inside the application bundle.

On a mac you can find some interesting sources in the app bundle at: Spotify.app/Contents/Resources/cef_views

Update: With the new version of the spotify preview, my solution does not fully apply anymore. You can still access some of the resources at Spotify.app/Contents/Resources/apps but they are now compressed into one file per app. However, you can still access some of the information by looking into these files.

tobias_
  • 468
  • 5
  • 21
  • 1
    Ah, thanks, the cef_views folder is very interesting. There you can find all the API scripts, css files etc. Super useful! – mbuchetics Dec 04 '11 at 16:10
  • Can't seem to find this folder on my MacBook (Spotify crashes whenever opening it by the way) and there seems to be no corresponding folder on Windows. Any clues? – Christian Dec 05 '11 at 23:11
  • 2
    In Windows the folder is located as a .zip file (resources.zip) in the data folder next so Spotify.exe. In my case this is 'C:\Users\buchetics\AppData\Roaming\Spotify\Data\resources.zip'. On the Mac, you need to right click Spotify.app and select 'Show Package Content' (or something like that), then you can navigate to the folder inside the bundle. – mbuchetics Dec 06 '11 at 08:03
  • Seems everything is compiled down into a .spa filetype. I find I'm able to use a hex editor to browse the contents, did you come up with a better way? – Brian Wigginton Dec 14 '11 at 00:14
  • 4
    You can extract the content with 'tar -xvf filename.spa'. – Ivan Navarrete Dec 22 '11 at 21:53
3

I just do a console.log on the "sp" object to trace out all objects that it contains. The sp objects has been named easily to undestand, so you can get a more indepth of the Spotify API. Example:

sp = getSpotifyApi(1);
toStringObject(sp);

function toStringObject(aObject, aTab){
  if(aTab == undefined || aTab == null){
    aTab = '';
  }
  for(var string in aObject){
    console.log(aTab + 'object: ' + string + ', value: ' + aObject[string]);
    if(typeof(aObject[string]) == 'object'){
      toStringObject(aObject[string], aTab + '\t');
      console.log('-------------------------------------');
    }
  }
}

Gives you the output:

...
    object: addEventListener, value: function addEventListener() { [native code] }
        object: hideSharePopup, value: function hideSharePopup() { [native code] }
    -------------------------------------
    object: trackPlayer, value: [object Object]
        object: setContextCanSkipPrev, value: function setContextCanSkipPrev() { [native code] }
        object: removeEventListener, value: function removeEventListener() { [native code] }
        object: setVolume, value: function setVolume() { [native code] }
        object: playTrackFromContext, value: function playTrackFromContext() { [native code] }
        object: canChangeRepeat, value: function canChangeRepeat() { [native code] }
        object: setShuffle, value: function setShuffle() { [native code] }
...
perborin
  • 234
  • 2
  • 10
2

A great way to see what is possible is to use the sample "api" app. Do that by typing "spotify:app:api" in the search box, and using the inspector to see what code is being included.

There is also a tutorial here: http://developer.spotify.com/download/spotify-apps-api/tutorial/

Hope this helps! Always contact mager@spotify.com too if you have questions.

mager
  • 4,813
  • 8
  • 29
  • 30
  • 3
    Can't get "spotify:app:api" to launch the app, I always get the "app not found" error message. Using the latest preview build (0.8.0.873). – mbuchetics Dec 12 '11 at 11:09
  • "The apps in this new preview version are currently unavailable outside of Spotify's launch countries, so you won't be able to play with them just yet." – Sucrenoir Dec 14 '11 at 15:21