I am working on another simple 'liker' twitter bot that I'm trying to host on Heroku based off your tutorial and how you mentioned the Heroku server to host.
I want it to like 10 tweets every 24hours regardless of whether my computer is on or off. I used the Heroku CLI to deploy the bot and it's been deployed here: https://liker-bot-1000.herokuapp.com/ , but alway the Application Error page. So I looked at the error log, added "start" to my package.json script, tried redeploying it, but it's still not there. Do you know if this is common server deployment problem?
2020-04-10T22:42:26.984600+00:00 heroku[web.1]: State changed from crashed to starting
2020-04-10T22:42:32.502164+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-10T22:42:32.416034+00:00 app[web.1]: npm ERR! missing script: start
2020-04-10T22:42:32.422742+00:00 app[web.1]:
2020-04-10T22:42:32.423021+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-04-10T22:42:32.423165+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-04-10T22_42_32_417Z-debug.log
2020-04-10T22:45:10.000000+00:00 app[api]: Build started by user [email protected]
2020-04-10T22:45:24.817287+00:00 heroku[web.1]: State changed from crashed to starting
2020-04-10T22:45:24.639590+00:00 app[api]: Deploy bfb99e88 by user [email protected]
2020-04-10T22:45:24.639590+00:00 app[api]: Release v7 created by user [email protected]
2020-04-10T22:45:25.000000+00:00 app[api]: Build succeeded
2020-04-10T22:45:30.198704+00:00 app[web.1]:
2020-04-10T22:45:30.198762+00:00 app[web.1]: > [email protected] start /app
2020-04-10T22:45:30.198763+00:00 app[web.1]: > node app.js
2020-04-10T22:45:30.198763+00:00 app[web.1]:
2020-04-10T22:46:27.364861+00:00 heroku[web.1]: State changed from starting to crashed
2020-04-10T22:46:29.142086+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=liker-bot-1000.herokuapp.com request_id=80bb8302-a75f-4c04-b785-1b9ae9840e50 fwd="76.169.98.201" dyno= connect= service= status=503 bytes= protocol=https
2020-04-10T22:46:31.050354+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=liker-bot-1000.herokuapp.com request_id=070f8fc7-a404-4770-82e6-e6b113919c63 fwd="76.169.98.201" dyno= connect= service= status=503 bytes= protocol=https
const Twitter = require('twitter');
const config = require('./config.js')
// configuration is set up.
const T = new Twitter(config);
const params = { // search parameters
q: '#dogs', // hashtag I'm searching for
count: 10, // number of tweets I'd like returned to me
result_type: 'recent', // only the most recent results
lang: 'en' // only in english.
}
setInterval(function() {
T.get('search/tweets', params, function(err, data, response) {
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.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);
}
})
}, 86400000); // 1000 * 60 * 60 * 24 = 86400000 milliseconds in 24-hours
{
"name": "twitter-bot",
"version": "1.0.0",
"description": "Nodejs Twitter liker Bot",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Stanley Jeong",
"license": "ISC",
"dependencies": {
"twitter": "^1.7.1"
}
}