By Gel


2017-12-05 15:24:56 8 Comments

===================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.

1 comments

@Gel 2017-12-12 16:38:11

  //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);    
            };
    });

Related Questions

Sponsored Content

5 Answered Questions

[SOLVED] How to tell if npm package was installed globally or locally

  • 2014-09-29 16:12:35
  • AndraeRay
  • 66151 View
  • 133 Score
  • 5 Answer
  • Tags:   node.js gruntjs npm

15 Answered Questions

[SOLVED] How to install an npm package from GitHub directly?

5 Answered Questions

[SOLVED] how to specify local modules as npm package dependencies

  • 2013-04-04 08:34:35
  • Sam Adams
  • 202025 View
  • 232 Score
  • 5 Answer
  • Tags:   node.js npm

6 Answered Questions

[SOLVED] npm - how to show the latest version of a package

15 Answered Questions

[SOLVED] Get data from fs.readFile

  • 2012-04-07 22:12:09
  • karaxuna
  • 496192 View
  • 281 Score
  • 15 Answer
  • Tags:   javascript node.js

15 Answered Questions

[SOLVED] How to list npm user-installed packages?

5 Answered Questions

[SOLVED] How to set custom location for local installation of npm package?

  • 2013-02-07 02:30:02
  • pje
  • 159654 View
  • 167 Score
  • 5 Answer
  • Tags:   node.js npm

1 Answered Questions

[SOLVED] YouTube API Error, Node.js

5 Answered Questions

[SOLVED] How do I uninstall a package installed using npm link?

  • 2013-09-30 12:44:43
  • nwinkler
  • 84659 View
  • 146 Score
  • 5 Answer
  • Tags:   node.js npm npm-link

5 Answered Questions

[SOLVED] NPM - How to fix "No readme data"

  • 2013-08-05 11:51:56
  • iancrowther
  • 63021 View
  • 188 Score
  • 5 Answer
  • Tags:   npm

Sponsored Content