Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何从spotify npm包中提取数据?我越来越不清楚了 ========================这是我下面的代码========================= 函数spotifyThisSong(){ var spotify=新spotif_Node.js_Npm - Fatal编程技术网

Node.js 如何从spotify npm包中提取数据?我越来越不清楚了 ========================这是我下面的代码========================= 函数spotifyThisSong(){ var spotify=新spotif

Node.js 如何从spotify npm包中提取数据?我越来越不清楚了 ========================这是我下面的代码========================= 函数spotifyThisSong(){ var spotify=新spotif,node.js,npm,Node.js,Npm,如何从spotify npm包中提取数据?我越来越不清楚了 ========================这是我下面的代码========================= 函数spotifyThisSong(){ var spotify=新spotify({ id:“myid”, 秘密:“我的秘密” }); var songName=process.argv[3]; 如果(!songName){ songName=“我又多大了”; } var params=songName; search(

如何从spotify npm包中提取数据?我越来越不清楚了 ========================这是我下面的代码========================= 函数spotifyThisSong(){ var spotify=新spotify({ id:“myid”, 秘密:“我的秘密” }); var songName=process.argv[3]; 如果(!songName){ songName=“我又多大了”; } var params=songName; search({type:'track',query:params},函数(err,data){ 如果(错误){ log('发生错误:'+err); return;//来自spotify npm文档 } 否则{ 控制台日志(数据); }; }); } ============================代码结束========================= 一直给我不确定的感觉。我需要提取歌曲名称,年份,专辑和它的网址。提前谢谢。
不可读,请正确格式化。您好,欢迎使用StackOverflow。请花些时间阅读帮助页面,特别是命名和的部分。更重要的是,请阅读。您可能还想了解。我很抱歉在没有编辑的情况下发布得太快。我希望这个版本更好。 ===================This is my code below========================= function spotifyThisSong() { var spotify = new Spotify({ id: 'myid', secret: 'mysecret' }); var songName = process.argv[3]; if(!songName){ songName = "What's my age again"; } var params = songName; spotify.search({ type: 'track', query: params }, function(err, data) { if ( err ) { console.log('Error occurred: ' + err); return; //from spotify npm docs } else{ console.log(data); }; }); } ===================END OF CODE========================= keeps giving me undefine. I need to extract the song name, year, album and its url. Thanks in advance.
  //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);    
            };
    });