Spotify Apps API: any more documentation?

不打扰是莪最后的温柔 提交于 2019-11-27 14:32:02

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.

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

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] }
...

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!