Git Product home page Git Product logo

random-image-twitterbot's Introduction

Tweetin'

random-image-twitterbot

A simple starter project for a Twitter bot that tweets random images.

  1. Clone/download this repo and install dependencies with npm install.
  2. Rename config-example.js to config.js and fill out the necessary information (see how).
  3. Put all your images into the images folder.
  4. Deploy your bot. Or remix it on Glitch.

Oh and definitely join Botmakers!

Notes

Use server-delete-images.js if you'd like to delete each image after posting it. Also, see server-attribution.js for an example how to credit the author if you're tweeting someone else's images.

random-image-twitterbot's People

Contributors

stefanbohacek avatar

Stargazers

 avatar João avatar Ꮹανiη Ꮐaмвoα avatar  avatar Salomé Pechin avatar Benjamin Albritton avatar cabbagesensual6457250 avatar B4Le avatar Schmidt avatar grdguez avatar Tugrul Erdem avatar @vicente avatar Perside Rosalie avatar Scott Davignon avatar Alex Drizos avatar cyruslk avatar  avatar Omar J. A. Holzknecht avatar beeman avatar Paul avatar Yisela Alvarez Trentini avatar Heather Jones avatar

Watchers

James Cloos avatar Yisela Alvarez Trentini avatar  avatar

random-image-twitterbot's Issues

Heroku hosting troubles

Hi Stefan,

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?

I'm on V7 (version 7) of my deployment to Heroku and here is my error log I get:

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

Here is my main app.js file:

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

and here is my package.json file:

{
  "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"
  }
}

thank you for any help!

'Read-only application cannot POST.' error message

HI fourtonfish,

I have cloned your project, only changed the console.js file like you said, i haven't added and photos or changed anything else. but when I run it in terminal using 'node server.js', I get this error. what am I doing wrong?

Opening an image...
Uploading an image...
ERROR:
Error: Read-only application cannot POST.
    at Object.exports.makeTwitError (/Users/stanleyjeong/Desktop/_CODING/twitter-bots/bot-take4-fourtonfish-github/random-image-twitterbot/node_modules/twit/lib/helpers.js:74:13)
    at onRequestComplete (/Users/stanleyjeong/Desktop/_CODING/twitter-bots/bot-take4-fourtonfish-github/random-image-twitterbot/node_modules/twit/lib/twitter.js:344:25)
    at Request.<anonymous> (/Users/stanleyjeong/Desktop/_CODING/twitter-bots/bot-take4-fourtonfish-github/random-image-twitterbot/node_modules/twit/lib/twitter.js:364:7)
    at Request.emit (events.js:327:22)
    at Gunzip.<anonymous> (/Users/stanleyjeong/Desktop/_CODING/twitter-bots/bot-take4-fourtonfish-github/random-image-twitterbot/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (events.js:421:28)
    at Gunzip.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1201:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  message: 'Read-only application cannot POST.',
  code: null,
  allErrors: [
    {
      request: '/1.1/media/upload.json',
      error: 'Read-only application cannot POST.'
    }
  ],
  twitterReply: {
    request: '/1.1/media/upload.json',
    error: 'Read-only application cannot POST.'
  },
  statusCode: 401
}

thank you for your help!

server-delete-images.js

Hi, I'm trying to use this bot to post some images on twitter. But for some reason, every time it sends the image and deletes it, the bot interrupts its operation. Is there any way to keep it working?

Thanks!

error twit config

Error: Twit config must include consumer_key when using user auth.

i am getting this error even though i have correctly put all my 4 keys in config.js

help

problem adding the delete code

New to this progamming and I couldn't place the code for deleting. Can anyone help?

fs.unlink(image_path, function(err){
if (err){
console.log('ERROR: unable to delete image ' + image_path);
}
else{
console.log('image ' + image_path + ' was deleted');
}
}

general message for each picture or unique message for each picture

Hi

I tried to insert T.post('statuses/update', { status: 'Look, I am tweeting!' } so that there could be a fixed message tweeted with each picture. I tried several combinations but it didn't work.

In one occasion it tweets the message in one tweet and tweets the picture in another.

It would actually be great if it would be possible to pull dedicated message for each picture. I saw a very close version but I couldn't make the Python and its code work.

It would be great if anyone can help.

Thank you
Best

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.