【问题标题】:Spotify - Search for an ArtistSpotify - 搜索艺术家
【发布时间】:2021-01-01 17:46:39
【问题描述】:

我遇到过这个演示 http://jsfiddle.net/JMPerez/0u0v7e1b/ 即使用 spotify API 搜索艺术家。 我已经尝试了很多尝试,但无法让它发挥作用。 有关如何工作的任何指示?

来自演示的 HTML 代码:

<div class="container">
<h1>Search for an Artist</h1>
<p>Type an artist name and click on "Search". Then, click on any album from the results to play 30 seconds of its first track.</p>
<form id="search-form">
    <input type="text" id="query" value="" class="form-control" placeholder="Type an Artist Name"/>
    <input type="submit" id="search" class="btn btn-primary" value="Search" />
</form>
<div id="results"></div>

【问题讨论】:

    标签: javascript html css api spotify


    【解决方案1】:

    此代码示例不起作用的原因是未提供令牌。如果您尝试访问https://api.spotify.com/v1/search,则该站点会返回:

    {
      "error": {
        "status": 401,
        "message": "No token provided"
      }
    }
    

    您可以在标头中附加令牌作为授权,类似于:

    $.ajax({
       url: 'https://api.spotify.com/v1/search',
       headers: {
          'Authorization': 'Bearer <token>'
       },
       success: function (result) {
           // CallBack(result);
       },
    });
    

    要获得开发者令牌,您可以查看 Spotify 的文档:https://developer.spotify.com/documentation/general/guides/authorization-guide/

    有关使用 Spotify 的 Web API 的更多信息,您还可以查看他们的快速入门指南:https://developer.spotify.com/documentation/web-api/quick-start/

    【讨论】:

      猜你喜欢
      • 2017-04-27
      • 2013-04-11
      • 2018-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多