简体   繁体   中英

Spotify Web JS wrapper-posting multiple tracks (not from playlist)

I am attempting to use the Spotify Web API JS wrapper from the following repo:

https://github.com/JMPerez/spotify-web-api-js

My goal here is to pull multiple tracks from Spotify and print them to a playlist on a webpage.The final version would ideally display up to 15 tracks at a time. Would this require an individual

  • for each? I'm pretty new to using API's so I will display the relevant JS and HTMl below for reference. Thank you for your help!

      var spotifyApi= new SpotifyWebApi(); //access token (optional) spotifyApi.setAccessToken(); Constr.prototype.getTracks = function(trackIds, options, callback) { var requestData = { url: _baseUri + '/tracks/', params: { ids: trackIds.join(',') } }; return _checkParamsAndPerformRequest(requestData, options, callback); }; 

    HTML

     <div class="playlist"> <p>Upload of tracks requires valid Spotify account</p> <a href="https://www.spotify.com/us/signup/">Sign up here</a> <div class="search"> <input type="search"> <p>Enter Artist Here</p> </div> <ul> <li type='none'id="tracks"> </li> </ul> </div><!--playlist--> 
  • There is an endpoint in the Spotify Web API for fetching multiple tracks at the same time that accepts an ids query parameter with comma separated track ids. That is the endpoint used in the getTracks() function of the wrapper you are using.

    From your question, I don't really know if you want to add those tracks to a playlist or if you want to render tracks from an artist.

    If you want to create a playlist with some tracks you will need the user to authorize your app. You have more information on the Authorization Guide .

    If you want to render tracks by an artist, you can also use some other endpoints like the one for getting an artist's top tracks .

    The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM