Question: The below code is utilizing nodejs to run some commands, with the help of apt npm packages. However, this example is not, yet. My terminal

The below code is utilizing nodejs to run some commands, with the help of apt npm packages. However, this example is not, yet. My terminal is taking issue with recognizing the get.client for the Twitter code (and that's from the npm package documentation) ... and that's toward the beginning. Requesting debugging.

// REQUIRE FILES var Twitter = require('twitter'); var twitterKeys = require('./keys.js');

var spotify = require('node-spotify-api'); var request = require('request'); var fs = require('fs');

// Twitter command if (process.argv[2] === "my-tweets") { // Using Twit constructor object to draw on Twitter API var client = twitterKeys; var params = { screen_name: 'MetalWorksWood', count: 20 }; client.get('statuses/user_timeline', params, function(error, tweets, response) { if(error) { console.log(error); } else { console.log(tweets); console.log(response); } });

// Spotify command } else if (process.argv[2] === "spotify-this-song") { var Spotify = require('node-spotify-api');

var spotify = new Spotify({ id: b55a9b13219744e8acc2593cf4c6016c, secret: c700dab217a54ae7b9895c98f299dd8e }); var song = process.argv; var songName = process.argv[3]

for (var i = 3; i < song.length; i++) { if (i > 3 && i < song.length) { songName = songName + "+" + song[i]; } else { songName += song[i]; }

spotify.search({ type: 'track', query: songName }, function(err, data) { console.log("******Spotify Response******"); console.log(data);

if (err) { console.log(err); } else if (!songName) { return console.log("Artist: Ace of Base Track: 'The Sign' Preview Link: 'https://open.spotify.com/track/3DYVWvPh3kGwPasp7yjahc' Album: 'The Sign' "); } else { console.log("Artist: " + data.artist +" Track: 'The Sign' Preview Link: 'https://open.spotify.com/track/3DYVWvPh3kGwPasp7yjahc' Album: 'The Sign' "); } }); } // OMBD Command } else if (process.argv[2] === "movie-this") { var nodeArgs = process.argv;

// Create an empty variable for holding the movie name var movieName = "";

// Loop through all the words in the node argument // And do a little for-loop magic to handle the inclusion of "+"s for (var i = 3; i < nodeArgs.length; i++) { if (i > 3 && i < nodeArgs.length) { movieName = movieName + "+" + nodeArgs[i]; } else { movieName += nodeArgs[i]; } }

// Then run a request to the OMDB API with the movie specified var queryUrl = "http://www.omdbapi.com/?t=" + movieName + "&y=&plot=short&apikey=40e9cece";

// This line is just to help us debug against the actual URL. console.log(queryUrl); request(queryUrl, function(error, response, body) {

// If the request is successful if (!error && response.statusCode === 200) { // Parse the body of the site and recover to output as so // title, year released, imdb rating, rotten tomatoes rating, country of production, movie language, movie plot, movie actors console.log("Title: " + JSON.parse(body).Title + " Release Year: " + JSON.parse(body).Year + " IMDB Rating: " + JSON.parse(body).imdbRating + " Rotten Tomatoes Rating: " + JSON.parse(body).Value + " Country Where Produced: " + JSON.parse(body).Country + " Language: " + JSON.parse(body).Language + " Plot: " + JSON.parse(body).Plot + " Actors: " + JSON.parse(body).Actors); } }); // Text Reader command } else if (process.argv[2] === "do-what-it-says") { fs.readFile("random.txt", "UTF-8", function(err, data) { if (err) { console.log(error); } console.log("node liri.js " + data); }); } else { console.log("Please try again. Command options are: 'my-tweets', 'spotify-this-song', 'movie-this', 'or do-what-it-says' "); }

keys.js

console.log('this is loaded');

var twitterKeys = { consumer_key: 'FAd8CKEvEEDKUETHbs2bUhhm1', consumer_secret: 'Ls6i1RqZQpTwN7m3H16EsBB4xjeDBVs0IFr6diy0j8St3f39T8', access_token_key: '913037658305294337-shH52SZKNwLBaCs1ddWa7UyamTL3lgL', access_token_secret: 'nXIN3AAicxVu28XnSyjsCXffqGsYIoU4sdm1sxElDcCEw', }

module.exports = twitterKeys;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!