【问题标题】:how to extract data from spotify npm package? I keep getting undefine如何从 spotify npm 包中提取数据?我一直不确定
【发布时间】:2017-12-13 00:38:11
【问题描述】:
===================这是我下面的代码========================= 函数 spotifyThisSong() { var spotify = 新的 Spotify({ id: 'myid', 秘密:“我的秘密” }); var songName = process.argv[3]; 如果(!歌曲名){ songName = "我又几岁了"; } 变量参数 = 歌曲名; spotify.search({ type: 'track', query: params }, function(err, data) { 如果(错误){ console.log('发生错误:' + err); 返回; //来自 spotify npm 文档 } 别的{ 控制台.log(数据); }; }); } ===================代码结束========================== 一直给我未定义。我需要提取歌曲名称、年份、专辑及其网址。提前致谢。

【问题讨论】:

标签: node.js npm


【解决方案1】:
  //So this is what I found.  This actually involves a few things.
  //FIRST, capture user-input,
  //SECOND, npm install spotify, and use the template as suggested in the DOCS. 
  //THIRD, parse through the JSON correctly as done below.

  //HOPE this helps someone.  (dont forget your keys from spotify)


  var songName = process.argv[3]; //capture userInput and query it below 

 params = songName;
    spotify.search({ type: 'track', query: params }, function(err, data) {
        if ( err ) {
            console.log('Error occurred: ' + err);
            return;  
        }
        else{
            output = space + "================= DATA HERE ==================" + 
            space + "Song Name: " + "'" +songName.toUpperCase()+ "'" +
            space + "Album Name: " + data.tracks.items[0].album.name +
            space + "Artist Name: " + data.tracks.items[0].album.artists[0].name +  
            space + "URL: " + data.tracks.items[0].album.external_urls.spotify + "\n\n\n";
            console.log(output);    
            };
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-06
    • 2013-07-04
    相关资源
    最近更新 更多