How to use Spotify Apps API objects?

The new Spotify Apps Javascript API contains a number of objects such as Album, Library, Link, etc. But how do you actually create an instance and use any of them in your application? I looked at the training application, but all that is used is the trackPlayer object, which is not documented as far as I can tell. The answer to this question involves searching the bundled applications in Spotify.app/Contents/Resources/cef_views. However, I cannot find this on my Mac and there seems to be no corresponding folder in Windows.

Any help would be greatly appreciated.

+4
source share
1 answer

First, to answer your second question about where to find the folder (I also posted this as a comment in my own original post):


On Windows, the folder is located as a .zip file ( resources.zip ) in the following Spotify.exe data folder. In my case it is

C: \ Users \ buchetics \ AppData \ Roaming \ Spotify \ Data \ resources.zip

On a 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 package.


Ok, now to your original question. You can get the API objects as follows:

 window.Models = sp.require("sp://import/scripts/api/models"); window.Views = sp.require("sp://import/scripts/api/views"); 

Then you can use all the methods and properties as described in the API link (which is still not very good). For instance:

 window.CurrentPlaylist = new Models.Playlist(); var track = Models.Track.fromURI("spotify:track:4n6AGL10M8fbm8oHxhK16j"); CurrentPlaylist.add(track); 

And so on. The model API is pretty easy to use, and the Views object can be used to display a list of tracks similar to regular Spotify lists. For other API calls, such as getting the current playback track, you need to use the base API, which will returend on var sp = getSpotifyApi(1); . However, there is no documentation for this yet, and it’s best to review the code found in cef_views , or use the Inspector in available applications to find useful code snippets (not all applications display their code in such a way that it’s easy to look at it, but some of which, for example, the application "We hunted" or "Sonki").

+6
source

Source: https://habr.com/ru/post/1384805/


All Articles