Last active
December 26, 2015 18:09
-
-
Save j127/7191906 to your computer and use it in GitHub Desktop.
How to use the Twit module to search tweets: 1. Install Node.js
2. Make a new folder and open it in the terminal.
3. Type: npm install twit
4. Create a file called app.js just above the node_modules directory that was automatically created by the previous command
5. Paste the code in from this Gist.
6. Add your Twitter API keys to the file and s…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import the twit module that was downloaded with npm install twit. | |
// The module is loaded in node_modules and Node.js knows where to find it. | |
var Twit = require('twit'); | |
// Settings -- put your keys here: | |
var T = new Twit({ | |
consumer_key: '...', | |
consumer_secret: '...', | |
access_token: '...', | |
access_token_secret: '...' | |
}); | |
// A method to search tweets. This will search for five JavaScript tweets from 2013. | |
T.get('search/tweets', { q: 'javascript since:2013-01-01', count: 5 }, function(err, reply) { | |
// Uncomment the next line to view the JSON that is returned | |
// console.log(reply); | |
// Extract the statuses | |
var tweets = reply.statuses; | |
// Loop over the tweets | |
for (var i = 0, len = tweets.length; i < len; i++) { | |
// Do stuff with the tweets here | |
console.log(tweets[i].text); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment