Skip to content

Instantly share code, notes, and snippets.

@olivmonnier
Forked from bmorelli25/app.js
Last active May 30, 2017 15:35
Show Gist options
  • Save olivmonnier/53ba6655c189bcf63eda2037d1b2fb88 to your computer and use it in GitHub Desktop.
Save olivmonnier/53ba6655c189bcf63eda2037d1b2fb88 to your computer and use it in GitHub Desktop.
Twitter Favorite Bot
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);
}
})
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