使用播放按钮和/或元数据API(Spotify)进行现场演示

Live demos with the Play Button and / or Metadata API (Spotify)

本文关键字:Spotify 现场 API 按钮 播放 元数据      更新时间:2023-09-26

是否对实现和工作的播放按钮和/或元数据API进行了任何实际操作(当然是本地Spotify之外)TR

在此处查看元文档:https://developer.spotify.com/technologies/web-api/search/


我无法创造一个可以看到任何东西的环境;用代码/API四处闲逛和尝试。我希望能够创建一个沙盒,看到任何可以在上面工作的东西。但这些文件似乎几乎不存在


本质上;我在跳组合;https://developer.spotify.com/technologies/widgets/spotify-play-button/

使用元搜索。

我理解我可以通过以下语法看到:http://ws.spotify.com/search/1/track.json?q=artist:foo+战斗机

但如何在它面前进行搜索;然后吐出来?这似乎是一个中间组件,我不知道该怎么办。

我只想创建一个搜索栏>>从该搜索栏中,您可以输入一个艺术家>>,点击Spotify>>并吐出艺术家的播放列表来收听。

我稍后会回去创建一个过滤器,只吐出在特定区域内举办活动或音乐会的艺术家

这个问题不一定与Spotify的Web API有关,而是使用服务器端脚本从Web API检索信息,并将结果传递给视图。正如在类似的问题中所回答的,API不支持CORS或JSONP。由于您不能向不同的域发出XMLHttpRequest,因此您必须制作服务器端脚本来向Web API发出HTTP请求。正如类似的帖子所说,你可以用多种语言来实现这一点,例如PHP、Python、Java或JavaScript。

JavaScript解决方案可以是使用Express Web服务器运行Node,该服务器使用needle向Web API发出HTTP请求,并将该请求的结果传递到浏览器视图。

类似

var express = require('express');
var app = express();
var needle = require('needle');
// Handle requests for http://localhost:3000/<some-artist-name>
app.get('/:artistname', function(req, res) {
  // Make request to Spotify's Web API for some artist name
  needle.get('http://ws.spotify.com/search/1/artist?q=artist:' + req.params.artistname, function(error, response, body) {
    // Most popular artist from search results
    var artistURI = body.artists[0];
    // Send a Spotify Play Button iframe for the artist URI
    res.send("<iframe src='https://embed.spotify.com/?uri=" + artistURI + "' width='300' height='380' frameborder='0' allowtransparency='true'></iframe>"); 
  });  
});
app.listen(3000);

请将其视为不适当详细的伪代码,并作为将Node与这两个特定模块一起使用的示例。你有很多选择。