-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (36 loc) · 1.11 KB
/
index.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
37
38
39
40
41
42
43
require('dotenv').config();
const Twitter = require('twitter');
const apiKeys = {
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
access_token_key: process.env.ACCESS_TOKEN_KEY,
access_token_secret: process.env.ACCESS_TOKEN_SECRET
}
const T = new Twitter(apiKeys);
// Set up your search parameters
const params = {
q: 'Cerner',
count: 10,
result_type: 'recent', // this can be 'recent' or 'mixed'
lang: 'en'
}
// Initiate your search using the above paramaters
T.get('search/tweets', params, (err, data, response) => {
// If there is no error, proceed
if(err){
return console.log(err);
}
// Loop through the returned tweets
const tweetsId = data.statuses
.map(tweet => ({ id: tweet.id_str }));
tweetsId.map(tweetId => {
T.post('favorites/create', tweetId, (err, response) => {
if(err){
return console.log(err[0].message);
}
const username = response.user.screen_name;
const favoritedTweetId = response.id_str;
console.log(`Favorited: https://twitter.com/${username}/status/${favoritedTweetId}`);
});
});
})