-
-
Save olivmonnier/53ba6655c189bcf63eda2037d1b2fb88 to your computer and use it in GitHub Desktop.
Twitter Favorite Bot
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
var Twitter = require('twitter'); | |
var config = require('./config.js'); | |
var T = new Twitter(config); | |
// Set up your search parameters | |
var params = { | |
q: '#nodejs', | |
count: 10, | |
result_type: 'recent', | |
lang: 'en' | |
} | |
// Initiate your search using the above paramaters | |
T.get('search/tweets', params, function(err, data, response) { | |
// If there is no error, proceed | |
if(!err){ | |
// Loop through the returned tweets | |
for(let i = 0; i < data.statuses.length; i++){ | |
// Get the tweet Id from the returned data | |
let id = { id: data.statuses[i].id_str } | |
// Try to Favorite the selected Tweet | |
T.post('favorites/create', id, function(err, response){ | |
// If the favorite fails, log the error message | |
if(err){ | |
console.log(err[0].message); | |
} | |
// If the favorite is successful, log the url of the tweet | |
else{ | |
let username = response.user.screen_name; | |
let tweetId = response.id_str; | |
console.log('Favorited: ', `https://twitter.com/${username}/status/${tweetId}`) | |
} | |
}); | |
} | |
} else { | |
console.log(err); | |
} | |
}) |
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
module.exports = { | |
consumer_key: '', | |
consumer_secret: '', | |
access_token_key: '', | |
access_token_secret: '' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment