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

时间:2013-11-20 20:48:38

标签: javascript web-applications spotify

播放按钮和/或元数据API的实施和工作是否有任何现场小提琴? (当然在本地Spotify之外)

在这里查看元文档: 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+fighters

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

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

我稍后会再回过头来创建一个过滤器,只吐出在特定区域内有活动或音乐会的艺术家。

1 个答案:

答案 0 :(得分:1)

此问题不一定与Spotify的Web API有关,而是使用服务器端脚本从Web API检索信息并将结果传递给视图。正如similar question中所述,API不支持CORSJSONP。而且,由于您can't make XMLHttpRequests to different domains,您必须制作服务器端脚本以向Web API发出HTTP请求。正如类似的帖子所说,你可以用多种语言来做到这一点,例如: PHP,Python,Java或JavaScript。

JavaScript解决方案可以是使用Express webserver运行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的示例。你有很多选择。