【问题标题】:How to get spotify artist id for the spotify endpoint url?如何获取 spotify 端点 url 的 spotify 艺术家 ID?
【发布时间】:2017-01-10 10:48:07
【问题描述】:

我正在尝试获取某位艺术家的前十首曲目,但我不知道如何获取该特定艺术家的 Spotify id?这是终点。

GET /v1/artists/{id}/top-tracks

前提是这样,我应该可以输入艺人名,并且应该得到前十首曲目的JSON数据。

function test() {
  var query = $('#searchArtist').val();
  console.log(query);
  $.ajax({
    url: 'https://api.spotify.com/v1/artists/' + query + '/top-tracks?country=IN',
    success: function(response) {
      console.log(response)
    }
  })
}
$('#search').on('click', test);

我应该先授权吗?因为我查了文档,获取前十曲目数据不需要授权。

另外,让您知道。这里没有后端环境,如文档中所述,简单的数据获取不需要它。

【问题讨论】:

  • 我猜你需要提出两个单独的请求,一个是获取艺术家 ID,另一个是获取热门曲目。

标签: javascript spotify


【解决方案1】:

TZHX 所说的。您需要两个单独的请求。浏览器中的 Javascript 不是我的主要环境。我将在 bash 中用 curl 和 jq 进行解释。希望它足够清楚。

$ API_ARTIST_URL=$(curl -s 'https://api.spotify.com/v1/search?q=Daft+Punk&type=artist' | jq -r '.artists.items[0].href')

$ echo $API_ARTIST_URL
https://api.spotify.com/v1/artists/4tZwfgrHOc3mvqYlEYSvVi

$ curl -s "$API_ARTIST_URL/top-tracks?country=US" | jq -r '.tracks[].name'
Get Lucky - Radio Edit
One More Time
Instant Crush
Get Lucky
Lose Yourself to Dance
Around The World
Harder Better Faster Stronger
Doin' it Right
Something About Us
Give Life Back to Music

另一个细节。 ?country=IN 不会产生任何结果,因为 Spotify 尚未在印度推出。

【讨论】:

  • 您好,感谢您的发帖。我已经想通了,我将其标记为最佳答案,以便任何正在寻找解决方案的人都可以参考它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-07
  • 1970-01-01
  • 2018-05-11
  • 1970-01-01
  • 1970-01-01
  • 2017-02-22
相关资源
最近更新 更多