I’m trying to figure out how to work with the different classes in the Spotify Apps Javascript API like Album, Library, Link and others. I can’t seem to find clear examples of how to create instances of these objects and use them in my application.
I checked the tutorial app but it only shows the trackPlayer object being used, and I can’t find documentation for that specific object anywhere. I also tried looking for examples in the app bundle directories but couldn’t locate them on my system.
Can someone provide a simple example of how to instantiate and work with these API objects? Even a basic code snippet would be really helpful to get me started.
Indeed, the Spotify Apps API documentation can be quite confusing, especially since it has been deprecated. To work with classes like Album or Link, you don’t instantiate them directly; instead, you retrieve them via the main Spotify API namespace. For example, if you’re looking for Album objects, you can access them through functions like spotify.core.library.getAlbums(). This will give you the Album objects you need to manipulate. Similarly, for the Link class, use spotify.core.link.createFromString() to generate links rather than attempting to instantiate them directly. As for the trackPlayer, you can find it under spotify.core.trackPlayer. Unfortunately, many relevant methods are outlined in the old API references, so consulting archived documentation may be necessary.
The Spotify Apps API can be difficult to navigate, especially since it doesn’t use traditional object-oriented methods. You generally don’t instantiate objects directly with new. Instead, access them through the main Spotify API, like using spotify.core.library.getArtists() for Library class methods, or spotify.core.link.createFromURI() for the Link class. These are more like utility functions. It might be helpful to explore the spotify.core object in your console to identify available methods, as the documentation can frequently lack detail.