Working with real data – fetching trending tweets
Many online entities format their response data as JSON and XML in their Application Programmer Interfaces (APIs) to expose pertinent information to third-party developers who can subsequently integrate this data into their applications.
One such online entity is Twitter. In this recipe, we are going to make a command-line application that makes two requests to Twitter's REST service. The first will retrieve the most popular current topics on Twitter and the second will return the most recent tweets regarding the hottest topic on Twitter.
Getting ready
Let's create a file and name it twitter_trends.js
. We'll also use the following third-party colors
module to make our output more beautiful:
npm install colors
We'll need to go through some steps to satisfy the authorization requirements of the Twitter API. First, let's go to http://dev.twitter.com/apps, and log in with our Twitter account if need be (or sign up for a Twitter account first). Once...