-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter-app.js
36 lines (30 loc) · 1.05 KB
/
twitter-app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var Twitter = require('twitter'),
app = require('express')();
var twitterClient = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});
function getTweets(req, res) {
var params = {screen_name: req.params.screen_name},
textOfTweets;
twitterClient.get('statuses/user_timeline', params, function (error, tweets, response) {
if (!error) {
textOfTweets = tweets.map(function (tweet) {
return tweet.text;
});
console.log(textOfTweets);
res.json(textOfTweets);
} else {
console.error(error);
res.status(500).json({error: 'Something went wrong!'});
}
});
}
// app routes:
app.get('/tweets/:screen_name', getTweets);
// start app listening
var port = process.env.VCAP_APP_PORT || 3000;
app.listen(port);
console.log('listening at:', port);