Hello Stack Overflow Community,
I have been cooking up a twitter bot that will retweet web development related content as a small side project following this tutorial at Rising Stack. LINK
Here is my code, I'm using node.js to create this and an NPM called 'TWIT'.
console.log('The follow/retweet bot is starting');
//Import statement fromt TWIT NPM && CONFIG with secret keys.
var Twit = require('twit');
var config = require('./config');
//Secret codes to connect to Twitter
var T = new Twit(config);
//RETWEET BOT ======================
//find the latest tweet according the query 'q' in params
var retweet = function retweetIt() {
var params = {
q: '#coding, #webdev, #webdevelopment, #nodejs' , //required
result_type: 'recent',
lang: 'en'
}
// for more parameters, see https://dev.twitter.com/rest/reference/get/search/tweets
T.get('search/tweets', params, function retweetIt(err, data) {
// if there no errors
if (!err) {
// grab ID of tweet to retweet
var retweetId = data.statuses[0].id_str;
// Tell TWITTER to retweet
T.post('statuses/retweet/:id', {
id: retweetId
}, function(err, response) {
if (response) {
console.log('Retweeted!!!');
}
// if there was an error while tweeting
if (err) {
console.log('Something went wrong while RETWEETING... Duplication maybe...');
}
});
}
// if unable to Search a tweet
else {
console.log('Something went wrong while SEARCHING...');
}
});
}
retweet();
//retweet every 5 minutes
setInterval(retweet, 1000*60*5);
When I run this in my terminal, the first thing I see is "The follow/retweet bot is starting!" Which is great, I know its starting.
Following after that the variable retweet runs the functions that make retweeting happen. However, when I do I get this:
I get BOTH the (err) and (response). I don't know much about duplications in code, but is it the function running multiple times and making an error message? I have had success with this particular build before, I have been able to post messages and retweet. Ideally I would like to retweet every 30 minutes or an hour.
Can someone explain 'duplication' and tell me what I'm doing wrong?
Thanks!
via btetrick
No comments:
Post a Comment