【问题标题】:Get the top tracks of a spotify artist in javascript using spotify-web-api-js使用 spotify-web-api-js 在 javascript 中获取 Spotify 艺术家的热门曲目
【发布时间】:2021-07-22 01:53:26
【问题描述】:

我正在制作一个网站,我想获得特定 spotify 艺术家的 4 首热门歌曲。我正在使用 spotify-web-api-js 与 api 交互。有谁知道怎么做? 我已经阅读了文档,但只看到它列在你可以做什么的列表中,而不是如何实现它。 谢谢!!

【问题讨论】:

    标签: javascript api spotify


    【解决方案1】:

    使用 spotify-web-api-js 的 .getArtistsTopTracks 方法。 例如:

    import Spotify from "spotify-web-api-js"
    const spotify = new Spotify()
    
    const artistId = [/* get spotify artist id */]
    const countryId = [/* US for united states */] 
    const options = { limit: 4 }
    
    spotify.getArtistTopTracks(artistId, countryId, options)
      .then(res => {
        
      })

    【讨论】:

    • 我试过了,但现在我得到了响应“没有提供令牌”,但仅限于 getArtistTopTracks 方法......
    【解决方案2】:

    我试过了,但现在我得到了“没有提供令牌”的响应,但仅限于 getArtistTopTracks 方法...

      var spotifyApi = new SpotifyWebApi()
    
      var prev = null;
      spotifyApi.setAccessToken('BQDMzbdpgo70xiwLSFZLy9ohKwBDn-sCbjM_COA5Km7guA386L_hDreT06DbFxKPfypZyemjYOe6OewK7uPpjqkZER58drhGDwhokOcGVL0jHNAt9Fa2PXTBVwLsZqtBUKdBMBMnXqKkv2IHeqyj9nmswHy6qgYJKsg')
      var searchartist = function(artistname) {
      spotifyApi.searchArtists(artistname).then(
        function (data) {
          console.log(data.artists.items[0].id);
          spotifyApi.getArtistTracks(data.artists.items[0].id).then(
            function (data) {
              console.log(data)
            },
            function (err) {
              console.error(err);
            }
          );
        },
        function (err) {
          console.error(err);
        }
      );
      };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-27
      • 2014-03-20
      • 2012-11-21
      • 2018-05-11
      • 2013-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多